Skip to content

Commit 126ed9c

Browse files
mlechuKristofferC
authored andcommitted
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. (cherry picked from commit 5ddcea7)
1 parent 54440bb commit 126ed9c

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
@@ -1895,7 +1895,7 @@
18951895
,(expand-update-operator op op= (car e) rhs T))))
18961896
(else
18971897
(if (and (pair? lhs) (eq? op= '=)
1898-
(not (memq (car lhs) '(|.| tuple vcat ncat typed_hcat typed_vcat typed_ncat))))
1898+
(not (memq (car lhs) '(|.| globalref tuple vcat ncat typed_hcat typed_vcat typed_ncat))))
18991899
(error (string "invalid assignment location \"" (deparse lhs) "\"")))
19001900
(expand-update-operator- op op= lhs rhs declT))))
19011901

test/syntax.jl

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

2532+
module M59008 # dotop with global LHS in macro
2533+
using Test
2534+
global a = 1
2535+
macro counter()
2536+
:(a += 1)
2537+
end
2538+
@test @counter() === 2 === a
2539+
end
2540+
25322541
# issue #37656
25332542
@test :(if true 'a' else 1 end) == Expr(:if, true, quote 'a' end, quote 1 end)
25342543

0 commit comments

Comments
 (0)