Parameters.jl
Parameters.jl copied to clipboard
Better backtraces
Use the trick Tim used in https://github.com/mauro3/SimpleTraits.jl/pull/6 to get better backtraces.
Probably use https://bramtayl.github.io/NumberedLines.jl/stable/
I started trying to work on this but I think the code surgery got a little out of hand. One reasonable first step would be to use MacroTools exclusively for expression decomposition. Then I could write a wrappers for macrotools such that any numbered line inputs will yield numbered line outputs. Then comes the question of how to put these pieces together, that is, which part of the generated code you want to point back to which original line.
Hi @bramtayl, thanks for looking into this! I'm not 100% sure that MacroTools will work for 100%, but using more MacroTools is definitely good. I think starting non-fancy and just referencing the first line of the type def would be fine.
But I'm off on holidays now and then crazy conference prep. So, don't expect much from me until the end of April.
I realized today I had been thinking about this wrong. It seems like you would want backtraces to point to lines in the Parameters.jl file in @with_kw and not to lines in user code (that should already be clear in the stack trace entry which points to the macrocall location). This is in fact already the case; if you @macroexpand @with_kw ... you'll see code chock full of references to lines in Parameters.jl.
Thanks for spending your brain cycles on this!
There is probably a bit of both, but I think more the user-code (I assume that the Parameters.jl code is bug free ;-). Example:
julia> using Parameters
julia> @with_kw type AA
b=c
end
AA
julia> AA()
ERROR: UndefVarError: c not defined
Stacktrace:
[1] AA() at /home/mauro/.julia/v0.6/Parameters/src/Parameters.jl:376
Here it would be better to point to the user-code.