Skip to content

Commit 0c382c2

Browse files
authored
lowering: fix lhs-decls not handling parameters (#47274)
This caused const to be dropped from declarations involving named tuple destructuring. Fixes #47168
1 parent 1e31390 commit 0c382c2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/julia-syntax.scm

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,18 +2910,17 @@
29102910
,(construct-loops (reverse itrs) (reverse iv))
29112911
,result)))))
29122912

2913-
(define (lhs-vars e)
2914-
(cond ((symdecl? e) (list (decl-var e)))
2915-
((and (pair? e) (eq? (car e) 'tuple))
2916-
(apply append (map lhs-vars (cdr e))))
2917-
(else '())))
2918-
29192913
(define (lhs-decls e)
29202914
(cond ((symdecl? e) (list e))
2921-
((and (pair? e) (eq? (car e) 'tuple))
2915+
((and (pair? e)
2916+
(or (eq? (car e) 'tuple)
2917+
(eq? (car e) 'parameters)))
29222918
(apply append (map lhs-decls (cdr e))))
29232919
(else '())))
29242920

2921+
(define (lhs-vars e)
2922+
(map decl-var (lhs-decls e)))
2923+
29252924
(define (all-decl-vars e) ;; map decl-var over every level of an assignment LHS
29262925
(cond ((eventually-call? e) e)
29272926
((decl? e) (decl-var e))

test/syntax.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,14 @@ end
848848
@test c8925 == 3 && isconst(@__MODULE__, :c8925)
849849
@test d8925 == 4 && isconst(@__MODULE__, :d8925)
850850

851+
# issue #47168
852+
let t47168 = (;a47168 = 1, b47168 = 2);
853+
global const (;a47168, b47168) = t47168
854+
@test a47168 == 1 && isconst(@__MODULE__, :a47168)
855+
@test b47168 == 2 && isconst(@__MODULE__, :b47168)
856+
end
857+
@test (let x = (;x=1); let (;x) = x; x; end, x; end) == (1, (x = 1,))
858+
851859
# issue #18754: parse ccall as a regular function
852860
@test Meta.parse("ccall([1], 2)[3]") == Expr(:ref, Expr(:call, :ccall, Expr(:vect, 1), 2), 3)
853861
@test Meta.parse("ccall(a).member") == Expr(:., Expr(:call, :ccall, :a), QuoteNode(:member))

0 commit comments

Comments
 (0)