diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2019-10-28 14:36:28 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2019-10-28 14:38:05 +0900 |
commit | cc5580f175bb55c9a1d7574c1861f405ee972617 (patch) | |
tree | a943ed1d5bbb1e9810f5bdba49526bdb50f1f3db | |
parent | a72cb6b11d777c2268831df4f21ab56851db425c (diff) | |
download | ruby-cc5580f175bb55c9a1d7574c1861f405ee972617.tar.gz |
fix bug in keyword + protected combination
Test included for the situation formerly was not working.
-rw-r--r-- | test/ruby/test_keyword.rb | 16 | ||||
-rw-r--r-- | vm_insnhelper.c | 11 |
2 files changed, 25 insertions, 2 deletions
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); |