Skip to content

Commit 03d7516

Browse files
pfitzsebaviatesk
andauthored
Fix toplevel-global behaviour in ExprSplitter (#511)
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
1 parent f612188 commit 03d7516

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/construct.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,12 @@ function push_modex!(iter::ExprSplitter, mod::Module, ex::Expr)
435435
if ex.head === :toplevel || ex.head === :block
436436
# Issue #427
437437
modifies_scope = false
438-
for a in ex.args
439-
if isa(a, Expr) && a.head (:local, :global)
440-
modifies_scope = true
441-
break
438+
if ex.head === :block
439+
for a in ex.args
440+
if isa(a, Expr) && a.head (:local, :global)
441+
modifies_scope = true
442+
break
443+
end
442444
end
443445
end
444446
push!(iter.index, modifies_scope ? 0 : 1)

test/toplevel.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,3 +540,25 @@ end
540540
modexs = collect(ExprSplitter(@__MODULE__, ex))
541541
@test length(modexs) == 3
542542
end
543+
544+
@testset "toplevel scope annotation" begin
545+
ex = Base.parse_input_line("""
546+
global foo_g = 10
547+
sin(foo_g)
548+
""")
549+
modexs = collect(ExprSplitter(@__MODULE__, ex))
550+
for (mod, ex) in modexs
551+
@test JuliaInterpreter.finish!(Frame(mod, ex), true) === nothing
552+
end
553+
@test length(modexs) == 2
554+
555+
ex = Base.parse_input_line("""
556+
local foo = 10
557+
sin(42)
558+
""")
559+
modexs = collect(ExprSplitter(@__MODULE__, ex))
560+
for (mod, ex) in modexs
561+
@test JuliaInterpreter.finish!(Frame(mod, ex), true) === nothing
562+
end
563+
@test length(modexs) == 2
564+
end

0 commit comments

Comments
 (0)