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
The following code raises a compile-time error (even with --prelude=empty):
deffooend
{% verbatim do%}
foo
{%end%}
This is the exception:
Crystal::Call#scope cannot be nil (NilAssertionError)
from /crystal/src/compiler/crystal/program.cr:463:5 in 'lookup_macro'
from /crystal/src/compiler/crystal/semantic/semantic_visitor.cr:301:19 in 'expand_macro:raise_on_missing_const'
from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /crystal/src/compiler/crystal/semantic/ast.cr:649:5 in 'expand_inline_macro'
[...]
Error: you've found a bug in the Crystal compiler. [...]
This only happens when there is no callee (A.foo() or 10.to_s do not raise).
This happens regardless of arguments to the method, other macro code inside the verbatim, other crystal code inside the macro, etc.
This only happens using verbatim. Using {% begin %}\{% if true %}\{% end %}{% end %} does not cause an error.
However, wrapping the verbatim code inside another macro works:
We can see that everything is executed normally once inside the Semantic (top level) phase.
But for some reason, the macro is executed again twice inside the Semantic (type declarations) phase.
And later, it is called again inside the Semantic (main) phase.
Of course, using verbatim here makes no sense.
This issue was also not found during actual development but while researching the compiler internals.
Because of this, a potential fix could be to make using verbatim raise a proper error when there is no existing macro context.
Still, it should be investigated why all this happens.
Bug Report
The following code raises a compile-time error (even with
--prelude=empty
):This is the exception:
This only happens when there is no callee (
A.foo()
or10.to_s
do not raise).This happens regardless of arguments to the method, other macro code inside the
verbatim
, other crystal code inside the macro, etc.This only happens using
verbatim
. Using{% begin %}\{% if true %}\{% end %}{% end %}
does not cause an error.However, wrapping the
verbatim
code inside another macro works:In general, using
verbatim
at top-level behaves weirdly.This code:
..prints the numbers "1 2 3 2 2 2" (in this order).
When running the above code with
crystal run --stats
, I get this output:We can see that everything is executed normally once inside the
Semantic (top level)
phase.But for some reason, the macro is executed again twice inside the
Semantic (type declarations)
phase.And later, it is called again inside the
Semantic (main)
phase.Of course, using
verbatim
here makes no sense.This issue was also not found during actual development but while researching the compiler internals.
Because of this, a potential fix could be to make using
verbatim
raise a proper error when there is no existing macro context.Still, it should be investigated why all this happens.
The text was updated successfully, but these errors were encountered: