From b42c8398ba84437cd6e96cbf6ccaf5ac5eff32b6 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Mon, 28 Apr 2025 14:54:39 -0400 Subject: [PATCH] Don't support blockarg in opt_new We don't calculate the correct argc so the bookkeeping slot is something else (unexpected) instead of Qnil (expected). --- insns.def | 4 +++- prism_compile.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/insns.def b/insns.def index b0c74df220..ba71e9f856 100644 --- a/insns.def +++ b/insns.def @@ -916,11 +916,13 @@ opt_new VALUE argc = vm_ci_argc(cd->ci); VALUE val = TOPN(argc); + // The bookkeeping slot should be empty. + RUBY_ASSERT(TOPN(argc + 1) == Qnil); + if (vm_method_cfunc_is(GET_ISEQ(), cd, val, rb_class_new_instance_pass_kw) && !(ruby_vm_event_flags & ISEQ_TRACE_EVENTS)) { RB_DEBUG_COUNTER_INC(opt_new_hit); val = rb_obj_alloc(val); TOPN(argc) = val; - RUBY_ASSERT(TOPN(argc + 1) == Qnil); TOPN(argc + 1) = val; } else { diff --git a/prism_compile.c b/prism_compile.c index 3688a1e515..71361e9aa9 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -3722,7 +3722,8 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c bool inline_new = ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction && method_id == rb_intern("new") && - call_node->block == NULL; + call_node->block == NULL && + (flags & VM_CALL_ARGS_BLOCKARG) == 0; if (inline_new) { if (LAST_ELEMENT(ret) == opt_new_prelude) {