From fbaadd1cfe7fbfd1b904f193f99d7c845a6ed804 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 30 Mar 2022 11:03:56 -0700 Subject: Do not autosplat array in block call just because keywords accepted If the block only accepts a single positional argument plus keywords, then do not autosplat. Still autosplat if the block accepts more than one positional argument in addition to keywords. Autosplatting a single positional argument plus keywords made sense in Ruby 2, since a final positional hash could be used as keywords, but it does not make sense in Ruby 3. Fixes [Bug #18633] --- spec/ruby/language/block_spec.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb index b2a3cc84c4..f213d68ba1 100644 --- a/spec/ruby/language/block_spec.rb +++ b/spec/ruby/language/block_spec.rb @@ -40,8 +40,17 @@ describe "A block yielded a single" do m([1, 2]) { |a=5, b, c, d| [a, b, c, d] }.should == [5, 1, 2, nil] end - it "assigns elements to required arguments when a keyword rest argument is present" do - m([1, 2]) { |a, **k| [a, k] }.should == [1, {}] + ruby_version_is "3.2" do + it "does not autosplat single argument to required arguments when a keyword rest argument is present" do + m([1, 2]) { |a, **k| [a, k] }.should == [[1, 2], {}] + end + end + + ruby_version_is ''..."3.2" do + # https://bugs.ruby-lang.org/issues/18633 + it "autosplats single argument to required arguments when a keyword rest argument is present" do + m([1, 2]) { |a, **k| [a, k] }.should == [1, {}] + end end ruby_version_is ''..."3.0" do -- cgit v1.2.3