diff --git a/src/interpreter.c b/src/interpreter.c index feb0bbbe168a45..7c1f44092aa053 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -751,14 +751,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 7e9f798156d4ca..f5be127e9db30b 100644 --- a/test/core.jl +++ b/test/core.jl @@ -6711,6 +6711,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]