From adbb0d94548114c24d61752525456312088bdd64 Mon Sep 17 00:00:00 2001 From: David Barton Date: Wed, 12 Sep 2018 19:44:55 +0100 Subject: [PATCH] Fix `let a; end` statements (#10) --- src/SoftGlobalScope.jl | 6 +++++- test/runtests.jl | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/SoftGlobalScope.jl b/src/SoftGlobalScope.jl index f6e1d4f..0be265c 100644 --- a/src/SoftGlobalScope.jl +++ b/src/SoftGlobalScope.jl @@ -86,13 +86,15 @@ 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 @@ -100,6 +102,8 @@ else 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 diff --git a/test/runtests.jl b/test/runtests.jl index 4f7da3b..b6fc2b7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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