Skip to content

Commit 5ddcea7

Browse files
authored
Allow globalref on lhs of op= (#59762)
Fix #59008. `globalref`s are OK to assign to. This check isn't actually necessary since we check the lhs again when re-expanding the assignment, and most of the forms allowed through aren't valid with a non-dotted `op=`, but deleting it makes some error messages worse.
1 parent e8667fb commit 5ddcea7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/julia-syntax.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@
19061906
,(expand-update-operator op op= (car e) rhs T))))
19071907
(else
19081908
(if (and (pair? lhs) (eq? op= '=)
1909-
(not (memq (car lhs) '(|.| tuple vcat ncat typed_hcat typed_vcat typed_ncat))))
1909+
(not (memq (car lhs) '(|.| globalref tuple vcat ncat typed_hcat typed_vcat typed_ncat))))
19101910
(error (string "invalid assignment location \"" (deparse lhs) "\"")))
19111911
(expand-update-operator- op op= lhs rhs declT))))
19121912

test/syntax.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,15 @@ end
26022602
@test ncalls_in_lowered(:((.+)(a, b .- (.^)(c, 2))), GlobalRef(Base, :BroadcastFunction)) == 0
26032603
end
26042604

2605+
module M59008 # dotop with global LHS in macro
2606+
using Test
2607+
global a = 1
2608+
macro counter()
2609+
:(a += 1)
2610+
end
2611+
@test @counter() === 2 === a
2612+
end
2613+
26052614
# issue #37656
26062615
@test :(if true 'a' else 1 end) == Expr(:if, true, quote 'a' end, quote 1 end)
26072616

0 commit comments

Comments
 (0)