IRubyObject savedError = context.runtime.getGlobalVariables().get("$!");
try {
result = coerceBody(context, other);
} catch (RaiseException e) {
RubyWarnings warnings = context.runtime.getWarnings();
warnings.warn("Numerical comparison operators will no more rescue exceptions of #coerce");
warnings.warn("in the next release. Return nil in #coerce if the coercion is impossible.");
if (err) {
coerceFailed(context, other);
} else {
context.runtime.getGlobalVariables().set("$!", savedError);
}
return null;
}
if (!(result instanceof RubyArray) || ((RubyArray) result).getLength() != 2) {
if (err) {
throw context.runtime.newTypeError("coerce must return [x, y]");
} else if (!result.isNil()) {
RubyWarnings warnings = context.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;
}
return (RubyArray) result;
}