Skip to content
Browse files
Fix rest arg recording in IRClosure (long commit msg for a 1 line-fix)
* Recording a rest arg for blocks involved creating a splat (just
  like in a method). However, the unsplat flag wasn't being set
  in IRClosure (unlike in a method).

* This bug only affected zsuper in a block that used by define_method.
  See output on example enclosed further below in master vs 1.7 ...
  zsuper from foo and bar emit different output which is broken.

  However, zsuper in define_method is no longer supported in
  Ruby 2.x, it appears. MRI throws the following RuntimeError:

"implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (RuntimeError)"

  So, this bug (or bugfix) is not really relevant anymore. Hence,
  I am not adding a test/spec to document this behavior, but including
  a test snippet for it in the commit message.

  We should simply get rid of this support and simplify the zsuper
  logic in the IRBuilder.

* I am fixing this here so I can work on #2409 and implement a clean fix
  without worrying about different behavior for methods and closures.

class C
  def foo(a, *b)
    p "foo-a: #{a}; foo-b[0]: #{b[0]}"

  def bar(a, *b)
    p "bar-a: #{a}; bar-b[0]: #{b[0]}"

class D < C
  def self.doit(&blk)
    define_method :foo, blk

  def bar(a, *b)

D.doit { |a, *b| super }

d =, 2, 3), 2, 3)
[subbu@earth ir] jruby /tmp/bug.rb
"bar-a: 1; bar-b[0]: 2"
"foo-a: 1; foo-b[0]: [2, 3]"
  • Loading branch information
subbuss committed Jan 5, 2015
1 parent 0562581 commit 5ef2a90
Showing 1 changed file with 1 addition and 1 deletion.
@@ -195,7 +195,7 @@ public void addInstr(Instr i) {
// FIXME: This lost encoding information when name was converted to string earlier in IRBuilder
keywordArgs.add(new KeyValuePair<Operand, Operand>(new Symbol(rkai.argName, USASCIIEncoding.INSTANCE), rkai.getResult()));
} else if (i instanceof ReceiveRestArgInstr) {
blockArgs.add(new Splat(((ReceiveRestArgInstr)i).getResult()));
blockArgs.add(new Splat(((ReceiveRestArgInstr)i).getResult(), true));
} else if (i instanceof ReceiveArgBase) {
blockArgs.add(((ReceiveArgBase) i).getResult());

0 comments on commit 5ef2a90

Please sign in to comment.