From b2b8306b469329ccd7f44dc4b62b7eeb344ed338 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 2 Jul 2024 13:54:23 -0400 Subject: [PATCH] Fix forwarding for optimized send Always treat forwarding as a complex call. --- bootstraptest/test_method.rb | 15 +++++++++++++++ vm_insnhelper.c | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bootstraptest/test_method.rb b/bootstraptest/test_method.rb index a5ea35dd4b..af9443b8c6 100644 --- a/bootstraptest/test_method.rb +++ b/bootstraptest/test_method.rb @@ -1359,3 +1359,18 @@ assert_equal 'ok', %q{ foo(*["bar"]) foo("baz") } + +assert_equal 'ok', %q{ + class C + def foo(b:) + b + end + end + + def foo(...) + C.new.send(...) + end + + foo(:foo, b: :ok) + foo(*["foo"], b: :ok) +} diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 88feba74b9..85eb8920b5 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -4363,10 +4363,10 @@ vm_call_opt_send(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct const struct rb_callinfo *ci = calling->cd->ci; int flags = vm_ci_flag(ci); - if (UNLIKELY(!(flags & VM_CALL_ARGS_SIMPLE) && + if (UNLIKELY((flags & VM_CALL_FORWARDING) || (!(flags & VM_CALL_ARGS_SIMPLE) && ((calling->argc == 1 && (flags & (VM_CALL_ARGS_SPLAT | VM_CALL_KW_SPLAT))) || (calling->argc == 2 && (flags & VM_CALL_ARGS_SPLAT) && (flags & VM_CALL_KW_SPLAT)) || - ((flags & VM_CALL_KWARG) && (vm_ci_kwarg(ci)->keyword_len == calling->argc))))) { + ((flags & VM_CALL_KWARG) && (vm_ci_kwarg(ci)->keyword_len == calling->argc)))))) { CC_SET_FASTPATH(calling->cc, vm_call_opt_send_complex, TRUE); return vm_call_opt_send_complex(ec, reg_cfp, calling); }