-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviorcompiler:loweringSyntax lowering (compiler front end, 2nd stage)Syntax lowering (compiler front end, 2nd stage)macros@macros@macros
Description
julia> count = 0
julia> macro counter(f)
:(begin
global count += 1
println(count)
$f
end)
end;
julia> @macroexpand @counter sin(1.1)
quote
global Main.count += 1
Main.println(Main.count)
Main.sin(1.1)
end
julia> @counter cos(1.1)
ERROR: syntax: invalid assignment location "Main.count" around REPL[34]:3
Stacktrace:
[1] top-level scope
@ REPL[35]:1
On the other hand, manually expanding the global count += 1
line makes this work
julia> macro counter(f)
:(begin
global count = count + 1
println(count)
$f
end)
end;
julia> @macroexpand @counter sin(1.1)
quote
global count = Main.count + 1
Main.println(Main.count)
Main.sin(1.1)
end
julia> @counter sin(1.1)
1
0.8912073600614354
This reproduces on multiple versions (1.11 and nightly at the very least)
Metadata
Metadata
Assignees
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviorcompiler:loweringSyntax lowering (compiler front end, 2nd stage)Syntax lowering (compiler front end, 2nd stage)macros@macros@macros