Skip to content

Commit

Permalink
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -483,15 +483,17 @@ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boo
}

private static RubyArray coerceResult(final Ruby runtime, final IRubyObject result, final boolean err) {
if ( ! (result instanceof RubyArray) || ((RubyArray) result).getLength() != 2 ) {
if ( err ) throw runtime.newTypeError("coerce must return [x, y]");
if (!(result instanceof RubyArray) || ((RubyArray) result).getLength() != 2 ) {
if (err) throw runtime.newTypeError("coerce must return [x, y]");

if (!result.isNil()) {
RubyWarnings warnings = runtime.getWarnings();
warnings.warn("Bad return value for #coerce, called by numerical comparison operators.");
warnings.warn("#coerce must return [x, y]. The next release will raise an error for this.");
}
return null;
}
else if ( ! result.isNil() ) {
RubyWarnings warnings = runtime.getWarnings();
warnings.warn("Bad return value for #coerce, called by numerical comparison operators.");
warnings.warn("#coerce must return [x, y]. The next release will raise an error for this.");
}

return (RubyArray) result;
}

0 comments on commit 9b5e691

Please sign in to comment.