Skip to content

Commit

Permalink
error if for outer is used with no existing outer var. fixes JuliaL…
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 8, 2017
1 parent 7e7300e commit c5a642d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,7 @@
(= ,state (call (top start) ,coll))
;; TODO avoid `local declared twice` error from this
;;,@(if outer? `((local ,lhs)) '())
,@(if outer? `((require-existing-local ,lhs)) '())
,(expand-forms
`(,while
(call (top !) (call (top done) ,coll ,state))
Expand Down Expand Up @@ -2599,10 +2600,14 @@
((eq? (car e) 'local) '(null)) ;; remove local decls
((eq? (car e) 'local-def) '(null)) ;; remove local decls
((eq? (car e) 'implicit-global) '(null)) ;; remove implicit-global decls
((eq? (car e) 'require-existing-local)
(if (not (memq (cadr e) env))
(error "no outer variable declaration exists for \"for outer\""))
'(null))
((eq? (car e) 'warn-if-existing)
(if (or (memq (cadr e) outerglobals) (memq (cadr e) implicitglobals))
`(warn-loop-var ,(cadr e))
'(null)))
(if (or (memq (cadr e) outerglobals) (memq (cadr e) implicitglobals))
`(warn-loop-var ,(cadr e))
'(null)))
((eq? (car e) 'lambda)
(let* ((lv (lam:vars e))
(env (append lv env))
Expand Down
16 changes: 16 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2934,6 +2934,22 @@ let
@test a == 1:2
end

# `for outer`
let
function forouter()
i = 1
for outer i = 2:3
end
return i
end
@test forouter() == 3
end

@test_throws ErrorException("syntax: no outer variable declaration exists for \"for outer\"") @eval function f()
for outer i = 1:2
end
end

# issue #11295
function f11295(x...)
call = Expr(x...)
Expand Down
12 changes: 7 additions & 5 deletions test/topology.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

pids = addprocs_with_testenv(4; topology="master_slave")
p1 = pids[1]
p2 = pids[2]

@test_throws RemoteException remotecall_fetch(()->remotecall_fetch(myid, p2), p1)
let p1 = pids[1], p2 = pids[2]
@test_throws RemoteException remotecall_fetch(()->remotecall_fetch(myid, p2), p1)
end

function test_worker_counts()
# check if the nprocs/nworkers/workers are the same on the remaining workers
Expand Down Expand Up @@ -77,8 +77,9 @@ while true
end
end

for outer p1 in workers()
for outer p2 in workers()
let p1, p2
for p1 in workers()
for p2 in workers()
i1 = map_pid_ident[p1]
i2 = map_pid_ident[p2]
if (iseven(i1) && iseven(i2)) || (isodd(i1) && isodd(i2))
Expand All @@ -88,6 +89,7 @@ for outer p1 in workers()
end
end
end
end

remove_workers_and_test()

Expand Down

0 comments on commit c5a642d

Please sign in to comment.