From f4394bbca361c2bb500f586ba0bf1bef8b919910 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 27 Sep 2019 13:35:29 -0700 Subject: Do not autosplat when calling procs that accept rest and keywords When providing a single array to a block that takes a splat, pass the array as one argument of the splat instead of as the splat itself, even if the block also accepts keyword arguments. Previously, this behavior was only used for blocks that did not accept keywords. Implements [Feature#16166] --- spec/ruby/language/block_spec.rb | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'spec/ruby/language') diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb index 1a8e79063d..99366006b0 100644 --- a/spec/ruby/language/block_spec.rb +++ b/spec/ruby/language/block_spec.rb @@ -76,18 +76,18 @@ describe "A block yielded a single" do result.should == [1, 2, [3], {x: 9}, 2, {}] end - it "does not treat final Hash as keyword arguments" do + it "does not treat final Hash as keyword arguments and does not autosplat" do result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 1, a: 10}, {}] + result.should == [[{"a" => 1, a: 10}], {}] end - it "does not call #to_hash on final argument to get keyword arguments" do + it "does not call #to_hash on final argument to get keyword arguments and does not autosplat" do suppress_keyword_warning do obj = mock("coerce block keyword arguments") obj.should_not_receive(:to_hash) result = m([obj]) { |a=nil, **b| [a, b] } - result.should == [obj, {}] + result.should == [[obj], {}] end end end @@ -113,12 +113,12 @@ describe "A block yielded a single" do end ruby_version_is "2.8" do - it "does not call #to_hash on the argument when optional argument and keyword argument accepted" do + it "does not call #to_hash on the argument when optional argument and keyword argument accepted and does not autosplat" do obj = mock("coerce block keyword arguments") obj.should_not_receive(:to_hash) result = m([obj]) { |a=nil, **b| [a, b] } - result.should == [obj, {}] + result.should == [[obj], {}] end end @@ -132,18 +132,27 @@ describe "A block yielded a single" do end end ruby_version_is "2.8" do - it "does not separates non-symbol keys and symbol keys" do + it "does not separate non-symbol keys and symbol keys and does not autosplat" do suppress_keyword_warning do result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 10, b: 2}, {}] + result.should == [[{"a" => 10, b: 2}], {}] end end end end - it "does not treat hashes with string keys as keyword arguments" do - result = m(["a" => 10]) { |a = nil, **b| [a, b] } - result.should == [{"a" => 10}, {}] + ruby_version_is ""..."2.8" do + it "does not treat hashes with string keys as keyword arguments" do + result = m(["a" => 10]) { |a = nil, **b| [a, b] } + result.should == [{"a" => 10}, {}] + end + end + + ruby_version_is "2.8" do + it "does not treat hashes with string keys as keyword arguments and does not autosplat" do + result = m(["a" => 10]) { |a = nil, **b| [a, b] } + result.should == [[{"a" => 10}], {}] + end end ruby_version_is ''...'2.8' do -- cgit v1.2.3