ruby-changes:58925
From: Jeremy <ko1@a...>
Date: Thu, 28 Nov 2019 03:03:57 +0900 (JST)
Subject: [ruby-changes:58925] 299a13612e (master): Don't modify rest array when using ruby2_keywords
https://git.ruby-lang.org/ruby.git/commit/?id=299a13612e From 299a13612e54accd9d3661bafde8f67142a78d54 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Wed, 27 Nov 2019 09:03:00 -0800 Subject: Don't modify rest array when using ruby2_keywords Previously, the rest array was modified, but it turns out that is not necessary. Not modifying the rest array fixes cases when the rest array is used more than once. diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index bbb107d..29335a4 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -2649,6 +2649,11 @@ 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_baz2(*args) + baz(*args) + baz(*args) + end + ruby2_keywords def foo_foo_bar(meth, *args) foo_bar(meth, *args) end @@ -2761,6 +2766,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L2766 h1 = {a: 1} o = c.new + assert_equal([1, h1], o.foo_baz2(1, :a=>1)) + assert_equal([1], o.foo_baz2(1, **{})) + assert_equal([h1], o.foo_baz2(h1, **{})) + 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.bfoo(:bar, 1, :a=>1)) diff --git a/vm_args.c b/vm_args.c index 78a0f0d..6729d54 100644 --- a/vm_args.c +++ b/vm_args.c @@ -742,7 +742,6 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L742 if (RB_TYPE_P(rest_last, T_HASH) && (((struct RHash *)rest_last)->basic.flags & RHASH_PASS_AS_KEYWORDS)) { 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; @@ -754,7 +753,7 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L753 } if (kw_flag & VM_CALL_KW_SPLAT) { - if (len > 0 && ignore_keyword_hash_p(RARRAY_AREF(args->rest, len - 1), iseq)) { + if (len > 0 && ignore_keyword_hash_p(rest_last, iseq)) { if (given_argc != min_argc) { if (remove_empty_keyword_hash) { arg_rest_dup(args); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/