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
def assert(cond, &err : -> String)
{% if flag?(:debug) %}
raise err.call unless cond
{% end %}
end
assert(false) { "test error" }
compile result
Showing last frame. Use --error-trace for full trace.
There was a problem expanding macro 'macro_140633862877744'
Called macro defined in eval:2:3
Which expanded to:
> 1 |
> 2 | raise err.call unless cond
^--
Error: undefined local variable or method 'err' for top-level
This is not exacty #7975. The variable is not declared within the macro. It's only used there.
But it seems to be a similar issue. The compiler determines whether a block argument is a caputered block depending on whether the variable is referenced in the method body. Apparently it cannot recognise it when inside a macro.
So this relates to #8764.
It's easy to work around by inserting an explicit reference to the block variable outside the macro.
my test code
compile result
try online: https://play.crystal-lang.org/#/r/gxy9
The text was updated successfully, but these errors were encountered: