This question comes from my project CrSignals. I have a macro to generate methods. The methods will report compile time error if it is called with invalid argument types. I find that the error leak the macro, and I don’t know how to hide the macro.
The example code
macro gen_foo
def foo(*args)
{% verbatim do %}
{% @def.name.raise "Oops!" %}
{% end %}
end
end
gen_foo
foo(1, 2, 3)
Compile without --error-trace
[developer@crystal-dev tmp]$ ../bin/crystal test1.cr
Using compiled compiler at /home/developer/workspace/.build/crystal
Showing last frame. Use --error-trace for full trace.
In test1.cr:9:1
9 | gen_foo
^
Error: Oops!
Compile with --error-trace
[developer@crystal-dev tmp]$ ../bin/crystal test1.cr --error-trace
Using compiled compiler at /home/developer/workspace/.build/crystal
In test1.cr:10:1
10 | foo(1, 2, 3)
^--
Error: instantiating 'foo(Int32, Int32, Int32)'
In test1.cr:9:1
9 | gen_foo
^
Error: Oops!
Purpose
Hide gen_foo
in error report.