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

ruby-changes:58431

From: Jeremy <ko1@a...>
Date: Fri, 25 Oct 2019 09:25:58 +0900 (JST)
Subject: [ruby-changes:58431] fb15e79403 (master): Handle case where ruby2_keywords method splats to ruby2_keywords method

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

From fb15e79403181098c969b4a8b7e4dd69f820955d Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Thu, 24 Oct 2019 12:36:49 -0700
Subject: Handle case where ruby2_keywords method splats to ruby2_keywords
 method

Previously, the keyword hash was duped (which results in a regular
hash), but the dup was not marked as a keyword hash, causing the
hash not to be marked as keyword hash even though it should be.

diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index 0f67c28..28a80fd1 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -2649,6 +2649,14 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L2649
         baz(*args)
       end
 
+      ruby2_keywords def foo_foo_bar(meth, *args)
+        foo_bar(meth, *args)
+      end
+
+      ruby2_keywords def foo_foo_baz(meth, *args)
+        foo_baz(meth, *args)
+      end
+
       ruby2_keywords def foo_mod(meth, *args)
         args << 1
         send(meth, *args)
@@ -2761,6 +2769,12 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L2769
     assert_equal([1, h1], o.store_foo(:baz, 1, :a=>1))
     assert_equal([[1], h1], o.foo_bar(1, :a=>1))
     assert_equal([1, h1], o.foo_baz(1, :a=>1))
+    assert_equal([[1], h1], o.foo(:foo, :bar, 1, :a=>1))
+    assert_equal([1, h1], o.foo(:foo, :baz, 1, :a=>1))
+    assert_equal([[1], h1], o.foo(:foo_bar, 1, :a=>1))
+    assert_equal([1, h1], o.foo(:foo_baz, 1, :a=>1))
+    assert_equal([[1], h1], o.foo_foo_bar(1, :a=>1))
+    assert_equal([1, h1], o.foo_foo_baz(1, :a=>1))
 
     assert_equal([[1], h1], o.foo(:bar, 1, **h1))
     assert_equal([1, h1], o.foo(:baz, 1, **h1))
@@ -2770,6 +2784,12 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L2784
     assert_equal([1, h1], o.store_foo(:baz, 1, **h1))
     assert_equal([[1], h1], o.foo_bar(1, **h1))
     assert_equal([1, h1], o.foo_baz(1, **h1))
+    assert_equal([[1], h1], o.foo(:foo, :bar, 1, **h1))
+    assert_equal([1, h1], o.foo(:foo, :baz, 1, **h1))
+    assert_equal([[1], h1], o.foo(:foo_bar, 1, **h1))
+    assert_equal([1, h1], o.foo(:foo_baz, 1, **h1))
+    assert_equal([[1], h1], o.foo_foo_bar(1, **h1))
+    assert_equal([1, h1], o.foo_foo_baz(1, **h1))
 
     assert_equal([[h1], {}], o.foo(:bar, h1, **{}))
     assert_equal([h1], o.foo(:baz, h1, **{}))
@@ -2779,6 +2799,12 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L2799
     assert_equal([h1], o.store_foo(:baz, h1, **{}))
     assert_equal([[h1], {}], o.foo_bar(h1, **{}))
     assert_equal([h1], o.foo_baz(h1, **{}))
+    assert_equal([[h1], {}], o.foo(:foo, :bar, h1, **{}))
+    assert_equal([h1], o.foo(:foo, :baz, h1, **{}))
+    assert_equal([[h1], {}], o.foo(:foo_bar, h1, **{}))
+    assert_equal([h1], o.foo(:foo_baz, h1, **{}))
+    assert_equal([[h1], {}], o.foo_foo_bar(h1, **{}))
+    assert_equal([h1], o.foo_foo_baz(h1, **{}))
 
     assert_warn(/The last argument is used as the keyword parameter.* for `bar'/m) do
       assert_equal([[1], h1], o.foo(:bar, 1, h1))
diff --git a/vm_args.c b/vm_args.c
index 6fce593..96fce15 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -740,6 +740,9 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L740
                 rest_last = rb_hash_dup(rest_last);
                 RARRAY_ASET(args->rest, len - 1, rest_last);
                 kw_flag |= VM_CALL_KW_SPLAT;
+                if (iseq->body->param.flags.ruby2_keywords) {
+                    remove_empty_keyword_hash = 0;
+                }
             }
             else {
                 rest_last = 0;
-- 
cgit v0.10.2


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

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