summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2024-01-31 11:07:45 -0800
committerJeremy Evans <code@jeremyevans.net>2024-01-31 12:44:38 -0800
commitc4697991264e473ac8295eea04de1d1ac04bec2f (patch)
tree430bc53bef21d11f2ccfa5abe13a7bba60666855 /test/ruby
parent71f16d498d30b3528774f519a0939eae59ef7602 (diff)
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.
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_keyword.rb18
1 files changed, 18 insertions, 0 deletions
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)