Skip to content

Commit ab74971

Browse files
authored
fix #25652, let scope error with destructuring (#25837)
1 parent 1d1a488 commit ab74971

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

Diff for: src/julia-syntax.scm

+15-5
Original file line numberDiff line numberDiff line change
@@ -1191,11 +1191,21 @@
11911191
(eq? (caadar binds) 'tuple))
11921192
(let ((vars (lhs-vars (cadar binds))))
11931193
(loop (cdr binds)
1194-
`(scope-block
1195-
(block
1196-
,@(map (lambda (v) `(local-def ,v)) vars)
1197-
,(car binds)
1198-
,blk)))))
1194+
(if (expr-contains-p (lambda (x) (memq x vars)) (caddr (car binds)))
1195+
;; use more careful lowering if there are name conflicts. issue #25652
1196+
(let ((temp (make-ssavalue)))
1197+
`(block
1198+
(= ,temp ,(caddr (car binds)))
1199+
(scope-block
1200+
(block
1201+
,@(map (lambda (v) `(local-def ,v)) vars)
1202+
(= ,(cadr (car binds)) ,temp)
1203+
,blk))))
1204+
`(scope-block
1205+
(block
1206+
,@(map (lambda (v) `(local-def ,v)) vars)
1207+
,(car binds)
1208+
,blk))))))
11991209
(else (error "invalid let syntax"))))
12001210
(else (error "invalid let syntax")))))))))
12011211

Diff for: test/core.jl

+9
Original file line numberDiff line numberDiff line change
@@ -3939,6 +3939,15 @@ let ex = quote
39393939
@test ex.args[2] == :test
39403940
end
39413941

3942+
# issue #25652
3943+
x25652 = 1
3944+
x25652_2 = let (x25652, _) = (x25652, nothing)
3945+
x25652 = x25652 + 1
3946+
x25652
3947+
end
3948+
@test x25652_2 == 2
3949+
@test x25652 == 1
3950+
39423951
# issue #15180
39433952
function f15180(x::T) where T
39443953
X = Vector{T}(uninitialized, 1)

0 commit comments

Comments
 (0)