Skip to content

Commit

Permalink
Fix toplevel-global behaviour in ExprSplitter (#511)
Browse files Browse the repository at this point in the history
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
  • Loading branch information
pfitzseb and aviatesk authored Jan 15, 2022
1 parent f612188 commit 03d7516
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/construct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions test/toplevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 03d7516

Please sign in to comment.