Skip to content

Commit 5ef2a90

Browse files
committed
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]}" end def bar(a, *b) p "bar-a: #{a}; bar-b[0]: #{b[0]}" end end class D < C def self.doit(&blk) define_method :foo, blk end def bar(a, *b) super end end D.doit { |a, *b| super } d = D.new d.bar(1, 2, 3) d.foo(1, 2, 3) -------------------------- [subbu@earth ir] jruby /tmp/bug.rb "bar-a: 1; bar-b[0]: 2" "foo-a: 1; foo-b[0]: [2, 3]" --------------------------
1 parent 0562581 commit 5ef2a90

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/src/main/java/org/jruby/ir/IRClosure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void addInstr(Instr i) {
195195
// FIXME: This lost encoding information when name was converted to string earlier in IRBuilder
196196
keywordArgs.add(new KeyValuePair<Operand, Operand>(new Symbol(rkai.argName, USASCIIEncoding.INSTANCE), rkai.getResult()));
197197
} else if (i instanceof ReceiveRestArgInstr) {
198-
blockArgs.add(new Splat(((ReceiveRestArgInstr)i).getResult()));
198+
blockArgs.add(new Splat(((ReceiveRestArgInstr)i).getResult(), true));
199199
} else if (i instanceof ReceiveArgBase) {
200200
blockArgs.add(((ReceiveArgBase) i).getResult());
201201
}

0 commit comments

Comments
 (0)