Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #18408, closure lowering of captured, never-assigned locals #18493

Merged
merged 1 commit into from
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,12 @@ f(x) = yt(x)
(if (eqv? (string.char (string name) 0) #\@)
(error "macro definition not allowed inside a local scope"))))
(if lam2
(lambda-optimize-vars! lam2))
(begin
;; mark all non-arguments as assigned, since locals that are never assigned
;; need to be handled the same as those that are (i.e., boxed).
(for-each (lambda (vi) (vinfo:set-asgn! vi #t))
(list-tail (car (lam:vinfo lam2)) (length (lam:args lam2))))
(lambda-optimize-vars! lam2)))
(if (not local) ;; not a local function; will not be closure converted to a new type
(cond (short e)
((null? cvs)
Expand Down Expand Up @@ -2992,6 +2997,8 @@ f(x) = yt(x)
'(null)
(convert-assignment name mk-closure fname lam interp)))))))
((lambda) ;; should only happen inside (thunk ...)
(for-each (lambda (vi) (vinfo:set-asgn! vi #t))
(car (lam:vinfo e)))
`(lambda ,(cadr e)
(,(clear-capture-bits (car (lam:vinfo e)))
() ,@(cddr (lam:vinfo e)))
Expand Down
8 changes: 8 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,14 @@ function capt_before_def()
end
@test capt_before_def()() == 2

function i18408()
local i
x->i
end
let f = i18408()
@test_throws UndefRefError f(0)
end

# variable scope, globals
glob_x = 23
function glotest()
Expand Down