-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
macros@macros@macros
Description
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:
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]:1Of 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).
Metadata
Metadata
Assignees
Labels
macros@macros@macros