From 493068b56b80cd4ca8f10813fcea25100e878c86 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 26 Sep 2018 13:03:57 -0400 Subject: [PATCH] fix crash when interpreting optimized top-level expressions (#29217) --- src/interpreter.c | 17 ++++++++++++++--- test/core.jl | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/interpreter.c b/src/interpreter.c index 6a12746341856..7e4b8be83a8ce 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -752,14 +752,25 @@ SECT_INTERP CALLBACK_ABI void *jl_interpret_call_callback(interpreter_state *s, locals[0] = (jl_value_t*)src; locals[1] = (jl_value_t*)stmts; s->src = src; - s->module = args->lam->def.method->module; + size_t nargs; + int isva; + if (jl_is_module(args->lam->def.value)) { + s->module = args->lam->def.module; + nargs = 0; + isva = 0; + } + else { + s->module = args->lam->def.method->module; + nargs = args->lam->def.method->nargs; + isva = args->lam->def.method->isva; + } s->locals = locals + 2; s->sparam_vals = args->lam->sparam_vals; s->continue_at = 0; s->mi = args->lam; size_t i; - for (i = 0; i < args->lam->def.method->nargs; i++) { - if (args->lam->def.method->isva && i == args->lam->def.method->nargs - 1) + for (i = 0; i < nargs; i++) { + if (isva && i == nargs - 1) s->locals[i] = jl_f_tuple(NULL, &args->args[i], args->nargs - i); else s->locals[i] = args->args[i]; diff --git a/test/core.jl b/test/core.jl index 906da539ec355..1f0c89b5fe529 100644 --- a/test/core.jl +++ b/test/core.jl @@ -6715,6 +6715,22 @@ struct T29145{A,B} end @test_throws TypeError T29145() +# interpreted but inferred/optimized top-level expressions with vars +let code = """ + while true + try + this_is_undefined_29213 + ed = 0 + break + finally + break + end + end + print(42) + """ + @test read(`$(Base.julia_cmd()) --startup-file=no --compile=min -e $code`, String) == "42" +end + # issue #29175 function f29175(tuple::T) where {T<:Tuple} prefix::Tuple{T.parameters[1:end-1]...} = tuple[1:length(T.parameters)-1]