Skip to content

Commit 8b5a844

Browse files
JeffBezansontkelman
authored andcommitted
fix #22032, for f() in 1:10 ...
(cherry picked from commit 03c5ad0) ref #22167
1 parent 341364f commit 8b5a844

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/julia-syntax.scm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,16 @@
14061406
,@(let loop ((lhs lhss)
14071407
(i 1))
14081408
(if (null? lhs) '((null))
1409-
(cons `(= ,(car lhs)
1410-
(call (core getfield) ,t ,i))
1409+
(cons (if (eventually-call (car lhs))
1410+
;; if this is a function assignment, avoid putting our ssavalue
1411+
;; inside the function and instead create a capture-able variable.
1412+
;; issue #22032
1413+
(let ((temp (gensy)))
1414+
`(block
1415+
(= ,temp (call (core getfield) ,t ,i))
1416+
(= ,(car lhs) ,temp)))
1417+
`(= ,(car lhs)
1418+
(call (core getfield) ,t ,i)))
14111419
(loop (cdr lhs)
14121420
(+ i 1)))))
14131421
,t)))

test/core.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,21 @@ end
539539
@test a[2](10) == 12
540540
@test a[3](10) == 13
541541

542+
# issue #22032
543+
let a = [], fs = []
544+
for f() in 1:3
545+
push!(a, f())
546+
push!(fs, f)
547+
end
548+
@test a == [1,2,3]
549+
@test [f() for f in fs] == [1,2,3]
550+
end
551+
let t = (22,33)
552+
(g(), x) = t
553+
@test g() == 22
554+
@test x == 33
555+
end
556+
542557
# issue #21900
543558
f21900_cnt = 0
544559
function f21900()

0 commit comments

Comments
 (0)