diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-03-30 11:03:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-30 11:03:56 -0700 |
commit | fbaadd1cfe7fbfd1b904f193f99d7c845a6ed804 (patch) | |
tree | 298c1393d770cc229d731b43ac13c793dcd93a36 /spec | |
parent | 75efbb98afe854972a1c832ec5d4d66639c41c74 (diff) | |
download | ruby-fbaadd1cfe7fbfd1b904f193f99d7c845a6ed804.tar.gz |
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]
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/language/block_spec.rb | 13 |
1 files changed, 11 insertions, 2 deletions
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 |