From 0d367ce65fe4e85f207a8ca5f1f331dd90c6992e Mon Sep 17 00:00:00 2001 From: Luke Gruber Date: Wed, 27 Aug 2025 09:26:57 -0400 Subject: Fix bad NameError raised using sendforward instruction through vcall If you called a VCALL method and the method takes forwarding arguments and then you forward those arguments along using the sendforward instruction, the method_missing class was wrongly chosen as NameError instead of NoMethodError. This is because the VM looked at the CallInfo of the vcall and determined it needed to raise NameError. Now we detect that case and raise NoMethodError. [Backport #21535] --- test/ruby/test_nomethod_error.rb | 28 ++++++++++++++++++++++++++++ vm_insnhelper.c | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/ruby/test_nomethod_error.rb b/test/ruby/test_nomethod_error.rb index 6d413e6391..aa2a88b2d8 100644 --- a/test/ruby/test_nomethod_error.rb +++ b/test/ruby/test_nomethod_error.rb @@ -106,4 +106,32 @@ class TestNoMethodError < Test::Unit::TestCase assert_match(/undefined method.+this_method_does_not_exist.+for.+Module/, err.to_s) end + + def test_send_forward_raises + t = EnvUtil.labeled_class("Test") do + def foo(...) + forward(...) + end + end + obj = t.new + assert_raise(NoMethodError) do + obj.foo + end + end + + # [Bug #21535] + def test_send_forward_raises_when_called_through_vcall + t = EnvUtil.labeled_class("Test") do + def foo(...) + forward(...) + end + def foo_indirect + foo # vcall + end + end + obj = t.new + assert_raise(NoMethodError) do + obj.foo_indirect + end + end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index c9e20e95b4..ac08a00600 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -4185,7 +4185,7 @@ static enum method_missing_reason ci_missing_reason(const struct rb_callinfo *ci) { enum method_missing_reason stat = MISSING_NOENTRY; - if (vm_ci_flag(ci) & VM_CALL_VCALL) stat |= MISSING_VCALL; + if (vm_ci_flag(ci) & VM_CALL_VCALL && !(vm_ci_flag(ci) & VM_CALL_FORWARDING)) stat |= MISSING_VCALL; if (vm_ci_flag(ci) & VM_CALL_FCALL) stat |= MISSING_FCALL; if (vm_ci_flag(ci) & VM_CALL_SUPER) stat |= MISSING_SUPER; return stat; -- cgit v1.2.3