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

add error message for attempting to capture a local variable as a closure type signature #23527

Merged
merged 1 commit into from
Sep 5, 2017
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
add error message for attempting to capture a local variable as a clo…
…sure type signature

fix #18730
  • Loading branch information
vtjnash committed Aug 31, 2017
commit d2562e6ffbaf48cad7e47153f6c8c364e391bdea
13 changes: 9 additions & 4 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3231,13 +3231,18 @@ f(x) = yt(x)
(capt-vars (diff all-capt-vars capt-sp)) ; remove capt-sp from capt-vars
(find-locals-in-method-sig (lambda (methdef)
(expr-find-all
(lambda (e) (and (pair? e) (eq? (car e) 'outerref)
(let ((s (cadr e)))
(lambda (e) (and (or (symbol? e) (and (pair? e) (eq? (car e) 'outerref)))
(let ((s (if (symbol? e) e (cadr e))))
(and (symbol? s)
(not (eq? name s))
(not (memq s capt-sp))
(or ;(local? s) ; TODO: error for local variables
(memq s (lam:sp lam)))))))
(if (and (local? s) (length> (lam:args lam) 0))
; error for local variables except in toplevel thunks
(error (string "local variable " s
" cannot be used in closure declaration"))
#t)
; allow captured variables
(memq s (lam:sp lam))))))
(caddr methdef)
(lambda (e) (cadr e)))))
(sig-locals (simple-sort
Expand Down
8 changes: 8 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1319,3 +1319,11 @@ let
@test f() == 0
@test f(2) == 2
end

# issue #18730
@test expand(Main, quote
function f()
local Int
x::Int -> 2
end
end) == Expr(:error, "local variable Int cannot be used in closure declaration")