diff --git a/src/toplevel.c b/src/toplevel.c index 0b752fb1c161e..6f29c0a82d617 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -874,8 +874,9 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int int has_ccall = 0, has_defs = 0, has_loops = 0, has_opaque = 0, forced_compile = 0; assert(head == jl_thunk_sym); thk = (jl_code_info_t*)jl_exprarg(ex, 0); - assert(jl_is_code_info(thk)); - assert(jl_typeis(thk->code, jl_array_any_type)); + if (!jl_is_code_info(thk) || !jl_typeis(thk->code, jl_array_any_type)) { + jl_eval_errorf(m, "malformed \"thunk\" statement"); + } body_attributes((jl_array_t*)thk->code, &has_ccall, &has_defs, &has_loops, &has_opaque, &forced_compile); jl_value_t *result; diff --git a/test/syntax.jl b/test/syntax.jl index 2410e5c8a8b62..32f343f4a392e 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -2330,7 +2330,7 @@ f35201(c) = h35201((;c...), k=true) f44343(;kw...) = NamedTuple(kw) @test f44343(u = (; :a => 1)) === (u = (; :a => 1),) -@testset "issue #34544/35367" begin +@testset "issue #34544/35367/35429" begin # Test these evals shouldn't segfault eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar1, Expr(:block))))) eval(Expr(:module, true, :bar2, Expr(:block))) @@ -2338,6 +2338,11 @@ f44343(;kw...) = NamedTuple(kw) @test_throws ErrorException eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar4, Expr(:quote))))) @test_throws ErrorException eval(Expr(:module, true, :bar5, Expr(:foo))) @test_throws ErrorException eval(Expr(:module, true, :bar6, Expr(:quote))) + + #35429 + @test_throws ErrorException eval(Expr(:thunk, x->x+9)) + @test_throws ErrorException eval(Expr(:thunk, Meta.parse("x=17"))) + @test_throws ErrorException eval(Expr(:thunk, Meta.parse("17"))) end # issue #35391