Skip to content

Commit

Permalink
Numeric and Comparable both rescue only StandardError in coerce.
Browse files Browse the repository at this point in the history
More warning reduction.
  • Loading branch information
headius committed Mar 4, 2015
1 parent fda635e commit 1479100
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyComparable.java
Expand Up @@ -145,8 +145,8 @@ private static IRubyObject callCmpMethod(ThreadContext context, IRubyObject recv

return RubyBoolean.newBoolean(runtime, cmpint(context, result, recv, other) == 0);
} catch (RaiseException e) {
cmpFailed(context);
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
cmpFailed(context);
// clear error info resulting from failure to compare (JRUBY-3292)
runtime.getGlobalVariables().set("$!", savedError);
return returnValueOnError;
Expand Down
18 changes: 11 additions & 7 deletions core/src/main/java/org/jruby/RubyNumeric.java
Expand Up @@ -473,14 +473,18 @@ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boo
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);
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
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);
}
context.runtime.getGlobalVariables().set("$!", savedError); // Restore $!
return null;
} else {
throw e;
}
context.runtime.getGlobalVariables().set("$!", savedError); // Restore $!
return null;
}

if (!(result instanceof RubyArray) || ((RubyArray) result).getLength() != 2) {
Expand Down

0 comments on commit 1479100

Please sign in to comment.