From c4697991264e473ac8295eea04de1d1ac04bec2f Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 31 Jan 2024 11:07:45 -0800 Subject: Do not modify provided argument splat when using ruby2_keywords with anonymous splat Previously, this would push the provided keywords onto the argument splat. Add ruby2_keywords to the list of other checks for whether it is safe for treating a given splat as mutable when the called method accepts an anonymous splat. --- test/ruby/test_keyword.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 7849fe285a..956cc9c56d 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -2809,6 +2809,24 @@ class TestKeywordArguments < Test::Unit::TestCase assert_raise(FrozenError) { c.send(:ruby2_keywords, :baz) } end + def test_anon_splat_ruby2_keywords + singleton_class.class_exec do + def bar(*a, **kw) + [a, kw] + end + + ruby2_keywords def bar_anon(*) + bar(*) + end + end + + a = [1, 2] + kw = {a: 1} + assert_equal([[1, 2], {a: 1}], bar_anon(*a, **kw)) + assert_equal([1, 2], a) + assert_equal({a: 1}, kw) + end + def test_top_ruby2_keywords assert_in_out_err([], <<-INPUT, ["[1, 2, 3]", "{:k=>1}"], []) def bar(*a, **kw) -- cgit v1.2.3