Skip to content

Commit fab13f2

Browse files
authoredJan 17, 2017
Merge pull request #19861 from JuliaLang/jn/toplevel_eval_world
run each Expr(toplevel) argument in the newest world
2 parents 4c9e948 + 4d82e2a commit fab13f2

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
 

‎src/toplevel.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,14 @@ jl_value_t *jl_toplevel_eval_flex(jl_value_t *e, int fast, int expanded)
606606
jl_sym_t *head = jl_is_expr(ex) ? ex->head : NULL;
607607

608608
if (head == toplevel_sym) {
609-
int i=0; jl_value_t *res=jl_nothing;
610-
for(i=0; i < jl_array_len(ex->args); i++) {
609+
size_t last_age = ptls->world_age;
610+
jl_value_t *res = jl_nothing;
611+
int i;
612+
for (i = 0; i < jl_array_len(ex->args); i++) {
613+
ptls->world_age = jl_world_counter; // eval each statement in the newest world age
611614
res = jl_toplevel_eval_flex(jl_array_ptr_ref(ex->args, i), fast, 0);
612615
}
616+
ptls->world_age = last_age;
613617
JL_GC_POP();
614618
return res;
615619
}

‎test/parse.jl

+20
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,26 @@ test_parseerror("0x1.0p", "invalid numeric constant \"0x1.0\"")
414414
try = "No"
415415
""")) == Expr(:error, "unexpected \"=\"")
416416

417+
# issue #19861 make sure macro-expansion happens in the newest world for top-level expression
418+
@test eval(Base.parse_input_line("""
419+
macro X19861()
420+
return 23341
421+
end
422+
@X19861
423+
""")::Expr) == 23341
424+
425+
# test parse_input_line for a streaming IO input
426+
let b = IOBuffer("""
427+
let x = x
428+
x
429+
end
430+
f()
431+
""")
432+
@test Base.parse_input_line(b) == Expr(:let, Expr(:block, Expr(:line, 2, :none), :x), Expr(:(=), :x, :x))
433+
@test Base.parse_input_line(b) == Expr(:call, :f)
434+
@test Base.parse_input_line(b) === nothing
435+
end
436+
417437
# issue #15763
418438
# TODO enable post-0.5
419439
#test_parseerror("if\nfalse\nend", "missing condition in \"if\" at none:1")

0 commit comments

Comments
 (0)
Please sign in to comment.