Skip to content
This repository

Fix for issue #276 #293

Closed
wants to merge 1 commit into from

2 participants

Sébastien Le Callonnec Charles Oliver Nutter
Sébastien Le Callonnec
Collaborator

This commit fixes issue #276 which is a regression introduced by
http://jira.codehaus.org/browse/JRUBY-6729. The bug was caused by a erroneous
behaviour when yielding splat for a block of arity of one: MRI doesn't unsplat
the passed value, whilst jruby was.

See GH-276_yield_splat_behaviour_causes_pp_to_break.rb for details on behaviour when yielding splat.

Sébastien Le Callonnec Fix for issue #276
This commit fixes issue #276 which is a regression introduced by
http://jira.codehaus.org/browse/JRUBY-6729.  The bug was caused by a erroneous
behavour when yielding splat for a block of arity of one: MRI doesn't unsplat
the passed value, whilst jruby was.

See GH-276_yield_splat_behaviour_causes_pp_to_break.rb for details on behaviour
a2c6561
Sébastien Le Callonnec

This restores the behaviour prior to JRUBY-6729

Charles Oliver Nutter
Owner

A-ha! Very good! I was hoping to find a fix for this issue. I'll have a look and get it merged if it's ok.

Charles Oliver Nutter headius closed this pull request from a commit September 18, 2012
Charles Oliver Nutter Additional fix to go with #276 and its fix #293.
* Compiler needed the same logic.
* Invalid block needs to be checked or arity().getValue will NPE.
da2a9dd
Charles Oliver Nutter headius closed this in da2a9dd September 18, 2012
प्रथमेश prathamesh-sonpatki referenced this pull request from a commit in prathamesh-sonpatki/jruby September 18, 2012
Charles Oliver Nutter Additional fix to go with #276 and its fix #293.
* Compiler needed the same logic.
* Invalid block needs to be checked or arity().getValue will NPE.
dc19d5d
प्रथमेश prathamesh-sonpatki referenced this pull request from a commit in prathamesh-sonpatki/jruby September 18, 2012
Charles Oliver Nutter Additional fix to go with #276 and its fix #293.
* Compiler needed the same logic.
* Invalid block needs to be checked or arity().getValue will NPE.
a0441ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 09, 2012
Sébastien Le Callonnec Fix for issue #276
This commit fixes issue #276 which is a regression introduced by
http://jira.codehaus.org/browse/JRUBY-6729.  The bug was caused by a erroneous
behavour when yielding splat for a block of arity of one: MRI doesn't unsplat
the passed value, whilst jruby was.

See GH-276_yield_splat_behaviour_causes_pp_to_break.rb for details on behaviour
a2c6561
This page is out of date. Refresh to see the latest.
55  spec/regression/GH-276_yield_splat_behaviour_causes_pp_to_break.rb
... ...
@@ -0,0 +1,55 @@
  1
+require 'rspec'
  2
+
  3
+def call_one
  4
+  yield(["a"])
  5
+end
  6
+
  7
+def call_two
  8
+  yield(["a","b"])
  9
+end
  10
+
  11
+def call_three
  12
+  yield(["a", "b", "c"])
  13
+end
  14
+
  15
+def yield_with_splat(method_name = 'call_two')
  16
+  send(method_name) { |*a| yield(*a) }
  17
+end
  18
+
  19
+describe 'yield splat' do
  20
+  it 'yields an array when block has only one argument' do
  21
+    value = nil
  22
+    yield_with_splat("call_one") { |a| value = a }
  23
+    value.should == ["a"]
  24
+  end
  25
+
  26
+  it 'yields an array when block as one argument and passed two' do
  27
+    value = nil
  28
+    yield_with_splat("call_two") { |a| value = a }
  29
+    value.should == ["a", "b"]
  30
+  end
  31
+
  32
+  it 'yields one value when block has two arguments and passed one' do
  33
+    first_value = nil
  34
+    second_value = nil
  35
+    yield_with_splat("call_one") { |a,b| first_value = a; second_value = b }
  36
+    first_value.should == "a"
  37
+    second_value.should == nil
  38
+  end
  39
+
  40
+  it 'yields two values when block has two arguments and passed two' do
  41
+    first_value = nil
  42
+    second_value = nil
  43
+    yield_with_splat { |a,b| first_value = a; second_value = b }
  44
+    first_value.should == "a"
  45
+    second_value.should == "b"
  46
+  end
  47
+
  48
+  it 'yields two values when block has two arguments and passed three' do
  49
+    first_value = nil
  50
+    second_value = nil
  51
+    yield_with_splat("call_three") { |a,b| first_value = a; second_value = b }
  52
+    first_value.should == "a"
  53
+    second_value.should == "b"
  54
+  end
  55
+end
5  src/org/jruby/ast/Yield19Node.java
@@ -24,12 +24,13 @@ public Yield19Node(ISourcePosition position, Node node) {
24 24
     public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
25 25
         Node args = getArgsNode();
26 26
         IRubyObject argsResult = args.interpret(runtime, context, self, aBlock);
  27
+        Block yieldToBlock = context.getCurrentFrame().getBlock();
27 28
 
28 29
         switch (args.getNodeType()) {
29 30
             case ARGSPUSHNODE:
30 31
             case ARGSCATNODE:
31 32
             case SPLATNODE: 
32  
-                argsResult = RuntimeHelpers.unsplatValue19(argsResult);
  33
+                if (yieldToBlock.arity().getValue() > 1) argsResult = RuntimeHelpers.unsplatValue19(argsResult);
33 34
                 break;
34 35
             case ARRAYNODE:
35 36
                 // Pass-thru
@@ -38,6 +39,6 @@ public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject se
38 39
                assert false: "Invalid node found in yield";
39 40
         }
40 41
 
41  
-        return context.getCurrentFrame().getBlock().yieldArray(context, argsResult, null, null);
  42
+        return yieldToBlock.yieldArray(context, argsResult, null, null);
42 43
     }
43 44
 }
3  src/org/jruby/javasupport/util/RuntimeHelpers.java
@@ -1820,8 +1820,7 @@ public static IRubyObject unsplatValue19(IRubyObject argsResult) {
1820 1820
                     
1821 1821
             if (array.size() == 1) {
1822 1822
                 IRubyObject newResult = array.eltInternal(0);
1823  
-                // JRUBY-6729. It seems RubyArray should be returned as it is from here.
1824  
-                if (!(newResult instanceof RubyArray)) {
  1823
+                if (!((newResult instanceof RubyArray) && ((RubyArray) newResult).size() == 0)) {
1825 1824
                     argsResult = newResult;
1826 1825
                 }
1827 1826
             }
6  test/externals/ruby1.9/test_pp.rb
@@ -137,6 +137,12 @@ def test_hash
137 137
     assert_equal("#{a.inspect}\n", PP.pp(a, ''))
138 138
   end
139 139
 
  140
+  def test_hash_with_boolean_value
  141
+    a = {}
  142
+    a[:b] = true
  143
+    assert_equal("{:b=>true}\n", PP.pp(a,''))
  144
+  end
  145
+
140 146
   S = Struct.new("S", :a, :b)
141 147
   def test_struct
142 148
     a = S.new(1,2)
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.