Skip to content
This repository

Don't expand "bar" in meth(*foo, bar) #2280

Merged
merged 2 commits into from about 1 year ago

2 participants

Leo Cassarani Dirkjan Bussink
Leo Cassarani
Collaborator

This fixes issue #2260 by wrapping final, non-splatted arguments in a singleton array, which the generated bytecode then concatenates onto the splatted ones, keeping the array "inside" intact. In other words, instead of the bytecode assembling the arguments for the call by doing something like:

[1, 2] + [3, 4]    # [1, 2, 3, 4]

We now do something like:

[1, 2] + [[3, 4]]  # [1, 2, [3, 4]]
Dirkjan Bussink dbussink merged commit c67e924 into from April 16, 2013
Dirkjan Bussink dbussink closed this April 16, 2013
Leo Cassarani leocassarani deleted the branch April 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
3  lib/compiler/ast/sends.rb
@@ -441,7 +441,8 @@ def initialize(line, arguments=nil)
441 441
             @array = []
442 442
           end
443 443
 
444  
-          @splat = CollectSplat.new line, arguments.arguments, arguments.value
  444
+          node = ArrayLiteral.new line, [arguments.value]
  445
+          @splat = CollectSplat.new line, arguments.arguments, node
445 446
         when ArrayLiteral
446 447
           @array = arguments.body
447 448
         when nil
5  spec/ruby/language/versions/send_1.9.rb
@@ -88,6 +88,11 @@
88 88
     specs.fooM4(0,*a,3).should == [0,1,2,3]
89 89
   end
90 90
 
  91
+  it "does not expand final array arguments after a splat expansion" do
  92
+    a = [1, 2]
  93
+    specs.fooM3(*a, [3, 4]).should == [1, 2, [3, 4]]
  94
+  end
  95
+
91 96
   it "accepts final explicit literal Hash arguments after the splat" do
92 97
     a = [1, 2]
93 98
     specs.fooM0RQ1(*a, { :a => 1 }).should == [[1, 2], { :a => 1 }]
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.