Skip to content

Commit

Permalink
JRUBY-6377: rspec .should include() fails in --1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Jan 24, 2012
1 parent 87afe49 commit 20341c0
Showing 1 changed file with 12 additions and 41 deletions.
53 changes: 12 additions & 41 deletions src/org/jruby/runtime/Interpreted19Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,63 +237,34 @@ private IRubyObject convertIfAlreadyArray(ThreadContext context, IRubyObject val
return value;
}

private boolean manyParms(boolean isRest, int requiredCount) {
/**
* We need to splat incoming array to a block when |a, *b| (any required +
* rest) or |a, b| (>1 required).
*/
private boolean needsSplat(boolean isRest, int requiredCount) {
return (isRest && requiredCount > 0) || (!isRest && requiredCount > 1);
}

private void setupBlockArg(ThreadContext context, IRubyObject value, IRubyObject self, Block block, Block.Type type) {
// System.out.println("AA: (" + value + ")");

int requiredCount = args.getRequiredArgsCount();
boolean isRest = args.getRestArg() != -1;

IRubyObject[] parameters;
if (value == null) {
parameters = IRubyObject.NULL_ARRAY;
} else if (manyParms(isRest, requiredCount)) {
if (value instanceof RubyArray) {
parameters = ((RubyArray) value).toJavaArray();
} else {
value = RuntimeHelpers.aryToAry(value);

parameters = (value instanceof RubyArray) ? ((RubyArray)value).toJavaArray() : new IRubyObject[] { value };
}
} else {
parameters = new IRubyObject[] { value };
}

if (!(args instanceof ArgsNoArgNode)) {
Ruby runtime = context.getRuntime();

// FIXME: This needs to happen for lambdas
// args.checkArgCount(runtime, parameters.length);
args.prepare(context, runtime, self, parameters, block);
}
setupBlockArgs(context, value, self, block, type, false);
}

// . Array given to rest should pass itself
// . Array with rest + other args should extract array
// . Array with multiple values and NO rest should extract args if there are more than one argument

// Note: In 1.9 alreadyArray is only relevent from our internal Java code in core libs. We never use it
// from interpreter or JIT. FIXME: Change core lib consumers to stop using alreadyArray param.
private void setupBlockArgs(ThreadContext context, IRubyObject value, IRubyObject self, Block block, Block.Type type, boolean alreadyArray) {
// System.out.println("AS: " + alreadyArray + "(" + value + ")");

int requiredCount = args.getRequiredArgsCount();
boolean isRest = args.getRestArg() != -1;
boolean needsSplat = needsSplat(isRest, requiredCount);
if (value != null && !(value instanceof RubyArray) && needsSplat) value = RuntimeHelpers.aryToAry(value);

IRubyObject[] parameters;
if (value == null) {
parameters = IRubyObject.NULL_ARRAY;
} else if (value instanceof RubyArray && (alreadyArray || (isRest && requiredCount > 0))) {
} else if (value instanceof RubyArray && (alreadyArray || needsSplat)) {
parameters = ((RubyArray) value).toJavaArray();
} else if (isRest || requiredCount > 0) {
// 1.7.0 rewrite cannot come fast enough...
if (value instanceof RubyArray) {
parameters = new IRubyObject[] { value };
} else {
value = RuntimeHelpers.aryToAry(value);

parameters = (value instanceof RubyArray) ? ((RubyArray)value).toJavaArray() : new IRubyObject[] { value };
}
} else {
parameters = new IRubyObject[] { value };
}
Expand Down

0 comments on commit 20341c0

Please sign in to comment.