diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 28a80fd198..bbb107dedd 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -4859,4 +4859,20 @@ class TestKeywordArgumentsSymProcRefinements < Test::Unit::TestCase assert_equal([1, h3], c.call(**h3, &:m2)) assert_equal([1, h3], c.call(a: 1, **h2, &:m2)) end + + def test_protected_kwarg + mock = Class.new do + def foo + bar('x', y: 'z') + end + protected + def bar(x, y) + nil + end + end + + assert_nothing_raised do + mock.new.foo + end + end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 211a525c4e..a4bc276f04 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2879,8 +2879,15 @@ vm_call_method(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_ca else { /* caching method info to dummy cc */ VM_ASSERT(cc->me != NULL); - struct rb_call_data cd_entry = *cd; - return vm_call_method_each_type(ec, cfp, calling, &cd_entry); + if (ci->flag & VM_CALL_KWARG) { + struct rb_kwarg_call_data *kcd = (void *)cd; + struct rb_kwarg_call_data cd_entry = *kcd; + return vm_call_method_each_type(ec, cfp, calling, (void *)&cd_entry); + } + else { + struct rb_call_data cd_entry = *cd; + return vm_call_method_each_type(ec, cfp, calling, &cd_entry); + } } } return vm_call_method_each_type(ec, cfp, calling, cd);