Skip to content

Commit

Permalink
Fix let a; end statements (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Barton authored and stevengj committed Sep 12, 2018
1 parent 6c0b88b commit adbb0d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/SoftGlobalScope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,24 @@ else

# Deal with assignments where the LHS is always local but the RHS might require global statements
# For example, with previously defined a, let a = (a = 1) ; end -> let a = (global a = 1) ; end
function localassignment(ex::Expr, globals, locals, insertglobal)
function localassignment(ex, globals, locals, insertglobal)
if isexpr(ex, :block)
args = []
for arg in ex.args
if isexpr(arg, :(=))
push!(args, Expr(arg.head, arg.args[1], _softscope(arg.args[2], globals, locals, insertglobal)))
union!(locals, localvars(arg.args[1]))
elseif arg isa Symbol
push!(args, arg)
else
error("Unknown syntax - please file an issue in the SoftGlobalScope.jl repository")
end
end
return Expr(ex.head, args...)
elseif isexpr(ex, :(=))
return Expr(ex.head, ex.args[1], _softscope(ex.args[2], globals, locals, insertglobal))
elseif ex isa Symbol
return ex
else
error("Unknown syntax - please file an issue in the SoftGlobalScope.jl repository")
end
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ end
@test softscope(TestMod, nl"sqrt((for i = 1:10; a+=1; end; a))") == nl"sqrt((for i = 1:10; global a+=1; end; a))"
@test softscope(TestMod, nl"let a = (local b = 2; a = 1), b = (b = 3); end") == nl"let a = (local b = 2; global a = 1), b = (b = 3); end"
@test softscope(TestMod, nl"f(a=(for i = 1:10; a+=1; end; a))") == nl"f(a=(for i = 1:10; global a+=1; end; a))"
@test softscope(TestMod, nl"let a; a = 1; end") == nl"let a; a = 1; end"
@test softscope(TestMod, nl"let a, b; a = 1; end") == nl"let a, b; a = 1; end"
end
end

Expand Down

0 comments on commit adbb0d9

Please sign in to comment.