Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6
-
Fix Version/s: JRuby 1.7.0.RC1
-
Component/s: Core Classes/Modules
-
Labels:None
-
Environment:osx snow leopard
-
Testcase included:yes
-
Number of attachments :
Description
class A
include Enumerable
def initialize
@hash = {:a => [1], :b => [2,3]}
end
def order
[:a, :b]
end
def each
order.each { |k| yield( k,@hash[k] ) }
self
end
end
A.new.each {|x, y| puts [x, y].inspect }
A.new.map.each {|x, y| puts [x, y].inspect }
# Expected output, seen on jruby1.8 and MRI1.9.2
# [:a, [1]]
# [:b, [2, 3]]
# [:a, [1]]
# [:b, [2, 3]]
# jruby1.9 output, last two lines are wrong
# [:a, [1]]
# [:b, [2, 3]]
# [:a, nil]
# [:b, nil]
This test case could perhaps be more minimal than it is, but it clearly displays the issue.
A fix that solves this but breaks other things:
diff --git a/src/org/jruby/RubyEnumerable.java b/src/org/jruby/RubyEnumerable.java index 65eceea..9d24ee7 100644 --- a/src/org/jruby/RubyEnumerable.java +++ b/src/org/jruby/RubyEnumerable.java @@ -724,7 +724,7 @@ public class RubyEnumerable { return collectCommon19(context, self, block, "map"); } - private static IRubyObject collectCommon19(ThreadContext context, IRubyObject self, final Block block, String methodName) { + private static IRubyObject collectCommon19(ThreadContext context, final IRubyObject self, final Block block, String methodName) { final Ruby runtime = context.getRuntime(); if (block.isGiven()) { final RubyArray result = runtime.newArray(); @@ -732,7 +732,7 @@ public class RubyEnumerable { callEach19(runtime, context, self, block.arity(), new BlockCallback() { public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) { IRubyObject larg = checkArgs(runtime, largs); - IRubyObject value = block.yield(ctx, larg); + IRubyObject value = block.yieldArray(ctx, RubyArray.newArrayNoCopy(runtime, largs), self, self.getMetaClass()); synchronized (result) { result.append(value); }I have half a mind to start ripping Enumerable logic out of Java code and reimplementing it in Ruby; the mess we have in RubyEnumerable now is getting to be unbearable.