How to change a module's source file attribute?

I thought about that but there are issues.

For example, if we do like this

q = quote do
def foo, do: 1/0
def bar, do: 2/0
end
Module.create(Y, q, Map.put(__ENV__, :file, "y.ex"))

then when calling Y.foo() and Y.bar() the lines in the stracktraces are the same. I think this is because quote does not add metadata line: number in this case (only when the quotes are generated by the compiler when calling macros do they get the line: number metadata).

I also tried to do quote location: :keep do ... but then the file is the physical file, not y.ex.

The only solution I found is to do Macro.postwalk to add the metadata keep: {"y.ex", number} on every node that has the metadata line: number.

This solution is working well, but a more direct way would be preferable. The possibilities are:

  1. have @file set the file for all following functions and macros, not only the next one

  2. support quote location: "filepath" do and quote lines: true do

In fact, I think both points 1) and 2) would be useful for my and other use cases.