From 3efbd527a86203406664a01126784a10eb136405 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 24 Jan 2020 12:13:41 -0800 Subject: Do not autosplat when calling proc with empty keyword splat With the removal of the splatted argument when using an empty keyword splat, the autosplat code considered an empty keyword splat the same as no argument at all. However, that results in autosplat behavior changing dependent on the content of the splatted hash, which is not what anyone would expect or want. This change always skips an autosplat if keywords were provided. Fixes [Bug #16560] (cherry picked from commit c1d8829ef515ee51fadeadd7dd022b5c47a71cdd) --- test/ruby/test_proc.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/ruby/test_proc.rb') diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index c6572ec1ba..3f0d599a04 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -1087,6 +1087,26 @@ class TestProc < Test::Unit::TestCase assert_equal([1,2,[3],4,5], r, "[ruby-core:19485]") end + def test_proc_autosplat + def self.a(arg, kw) + yield arg + yield arg, **kw + yield arg, kw + end + + arr = [] + a([1,2,3], {}) do |arg1, arg2=0| + arr << [arg1, arg2] + end + assert_equal([[1, 2], [[1, 2, 3], 0], [[1, 2, 3], {}]], arr) + + arr = [] + a([1,2,3], a: 1) do |arg1, arg2=0| + arr << [arg1, arg2] + end + assert_equal([[1, 2], [[1, 2, 3], {a: 1}], [[1, 2, 3], {a: 1}]], arr) + end + def test_parameters assert_equal([], proc {}.parameters) assert_equal([], proc {||}.parameters) -- cgit v1.2.3