Skip to content

Commit

Permalink
Merge pull request #22167 from JuliaLang/jb/fix22032
Browse files Browse the repository at this point in the history
fix #22032, `for f() in 1:10 ...`
  • Loading branch information
JeffBezanson authored Jun 1, 2017
2 parents ce1e3a5 + 03c5ad0 commit e36e412
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1407,8 +1407,16 @@
,@(let loop ((lhs lhss)
(i 1))
(if (null? lhs) '((null))
(cons `(= ,(car lhs)
(call (core getfield) ,t ,i))
(cons (if (eventually-call (car lhs))
;; if this is a function assignment, avoid putting our ssavalue
;; inside the function and instead create a capture-able variable.
;; issue #22032
(let ((temp (gensy)))
`(block
(= ,temp (call (core getfield) ,t ,i))
(= ,(car lhs) ,temp)))
`(= ,(car lhs)
(call (core getfield) ,t ,i)))
(loop (cdr lhs)
(+ i 1)))))
,t)))
Expand Down
15 changes: 15 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,21 @@ end
@test a[2](10) == 12
@test a[3](10) == 13

# issue #22032
let a = [], fs = []
for f() in 1:3
push!(a, f())
push!(fs, f)
end
@test a == [1,2,3]
@test [f() for f in fs] == [1,2,3]
end
let t = (22,33)
(g(), x) = t
@test g() == 22
@test x == 33
end

# issue #21900
f21900_cnt = 0
function f21900()
Expand Down

0 comments on commit e36e412

Please sign in to comment.