We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider a macro that defines a simple struct:
julia> macro bar() Expr(:struct, true, :Bar, Expr(:block, Expr(:(::), :field, :Int))) end @bar (macro with 1 method) julia> @macroexpand @bar :(mutable struct Bar field::Main.Int end) julia> @bar julia> Bar(4) Bar(4)
No problem.
Mark the field as const and the hygiene pass starts believing field is a variable instead of a field:
const
field
julia> macro foo() Expr(:struct, true, :Foo, Expr(:block, Expr(:const, Expr(:(::), :field, :Int)))) end @foo (macro with 1 method) julia> @macroexpand @foo :(mutable struct Foo const Main.field::Main.Int end)
resulting in the confusing error message:
julia> @foo ERROR: syntax: expected assignment after "const" around REPL[7]:1 Stacktrace: [1] top-level scope @ REPL[7]:1
Of course a solution consists in wrapping :field in an esc call, but that shouldn't be necessary (since it's not necessary in the first case).
:field
esc
The text was updated successfully, but these errors were encountered:
macroexpand: handle const/atomic struct fields correctly (#51980)
924aac9
Fixes #51899
2d6af7e
Fixes #51899 (cherry picked from commit 924aac9)
Successfully merging a pull request may close this issue.
Consider a macro that defines a simple struct:
No problem.
Mark the field as
const
and the hygiene pass starts believingfield
is a variable instead of a field:resulting in the confusing error message:
Of course a solution consists in wrapping
:field
in anesc
call, but that shouldn't be necessary (since it's not necessary in the first case).The text was updated successfully, but these errors were encountered: