You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say I have something like this that generates quite a bit of code
macrogen_tag_helpers
{%for tag in [:a, :img, :hr, :div, :many_more_tags] %}
def{{tag.id }}(text)
puts text.upcase
end
{%end%}
end
gen_tag_helpers
not_string =1# This will blow up because `1` does not implement `upcase`
img(not_string)
The output is this:
Error in macro_errors.cr:12: instantiating 'img(Int32)'
img(not_string)
^~~
in macro_errors.cr:9: expanding macro
gen_tag_helpers
^
in macro 'gen_tag_helpers' /Users/paulcsmith/learning/crystal-playground/macro_errors.cr:1, line 7:
1.
2. def a(text)
3. puts text.upcase
4. end
5.
6. def img(text)
> 7. puts text.upcase
8. end
9.
10. def hr(text)
11. puts text.upcase
12. end
13.
14. def div(text)
15. puts text.upcase
16. end
17.
+ many many more lines!
undefined method 'upcase' for Int32
Rerun with --error-trace to show a complete error trace.
The problem here is that I would expect this to be last
img(not_string)
^~~
It is super helpful that the compiler prints the macro so you can see what's wrong, but sometimes macros generate a bunch of code so finding the line that's the problem can be quite difficult. I wonder if it could print just some of the code. Maybe the 10 lines around the failure area with a compiler flag for showing everything if it's not enough. In my experience only a few lines of context are needed to see what the problem is.
It may also be helpful to colorize the line as :red so it draws attention, but that may be a separate issue.
Thanks for taking a look. Crystal rocks!
The text was updated successfully, but these errors were encountered:
Let's say I have something like this that generates quite a bit of code
The output is this:
The problem here is that I would expect this to be last
It is super helpful that the compiler prints the macro so you can see what's wrong, but sometimes macros generate a bunch of code so finding the line that's the problem can be quite difficult. I wonder if it could print just some of the code. Maybe the 10 lines around the failure area with a compiler flag for showing everything if it's not enough. In my experience only a few lines of context are needed to see what the problem is.
It may also be helpful to colorize the line as
:red
so it draws attention, but that may be a separate issue.Thanks for taking a look. Crystal rocks!
The text was updated successfully, but these errors were encountered: