[前][次][番号順一覧][スレッド一覧]

ruby-changes:58469

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 28 Oct 2019 14:38:42 +0900 (JST)
Subject: [ruby-changes:58469] cc5580f175 (master): fix bug in keyword + protected combination

https://git.ruby-lang.org/ruby.git/commit/?id=cc5580f175

From cc5580f175bb55c9a1d7574c1861f405ee972617 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Mon, 28 Oct 2019 14:36:28 +0900
Subject: fix bug in keyword + protected combination

Test included for the situation formerly was not working.

diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index 28a80fd1..bbb107d 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -4859,4 +4859,20 @@ class TestKeywordArgumentsSymProcRefinements < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L4859
     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 211a525..a4bc276 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 https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2879
 		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);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]