diff --git a/src/construct.jl b/src/construct.jl index 2b2c3d9b..86e15e2e 100644 --- a/src/construct.jl +++ b/src/construct.jl @@ -435,10 +435,12 @@ function push_modex!(iter::ExprSplitter, mod::Module, ex::Expr) if ex.head === :toplevel || ex.head === :block # Issue #427 modifies_scope = false - for a in ex.args - if isa(a, Expr) && a.head ∈ (:local, :global) - modifies_scope = true - break + if ex.head === :block + for a in ex.args + if isa(a, Expr) && a.head ∈ (:local, :global) + modifies_scope = true + break + end end end push!(iter.index, modifies_scope ? 0 : 1) diff --git a/test/toplevel.jl b/test/toplevel.jl index 88b74500..f0893c0f 100644 --- a/test/toplevel.jl +++ b/test/toplevel.jl @@ -540,3 +540,25 @@ end modexs = collect(ExprSplitter(@__MODULE__, ex)) @test length(modexs) == 3 end + +@testset "toplevel scope annotation" begin + ex = Base.parse_input_line(""" + global foo_g = 10 + sin(foo_g) + """) + modexs = collect(ExprSplitter(@__MODULE__, ex)) + for (mod, ex) in modexs + @test JuliaInterpreter.finish!(Frame(mod, ex), true) === nothing + end + @test length(modexs) == 2 + + ex = Base.parse_input_line(""" + local foo = 10 + sin(42) + """) + modexs = collect(ExprSplitter(@__MODULE__, ex)) + for (mod, ex) in modexs + @test JuliaInterpreter.finish!(Frame(mod, ex), true) === nothing + end + @test length(modexs) == 2 +end \ No newline at end of file