Skip to content

Commit

Permalink
fix #48889, bug in capturing variable declared outside while
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 31, 2023
1 parent f4cb8bc commit 0bb4e2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3718,6 +3718,7 @@ f(x) = yt(x)
;; Try to identify never-undef variables, and then clear the `captured` flag for single-assigned,
;; never-undef variables to avoid allocating unnecessary `Box`es.
(define (lambda-optimize-vars! lam)
;(prn lam)
(assert (eq? (car lam) 'lambda))
;; memoize all-methods-for to avoid O(n^2) behavior
(define allmethods-table (table))
Expand Down Expand Up @@ -3812,8 +3813,6 @@ f(x) = yt(x)
(let ((prev (table.clone live))
(decl- (table.clone decl)))
(let ((result (eager-any visit (cdr e))))
(if (eq? (car e) '_while)
(kill)) ;; body might not have run
(leave-loop! decl-)
(if result
#t
Expand Down
15 changes: 15 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5403,6 +5403,21 @@ function g37690()
end
@test g37690().x === 0

# issue #48889
function f48889()
let j=0, f, i
while j < 3
i = j + 1
if j == 0
f = ()->i
end
j += 1
end
f
end
end
@test f48889()() == 3

function _assigns_and_captures_arg(a)
a = a
return ()->a
Expand Down

0 comments on commit 0bb4e2b

Please sign in to comment.