Skip to content

Commit 1479100

Browse files
committed
Numeric and Comparable both rescue only StandardError in coerce.
More warning reduction.
1 parent fda635e commit 1479100

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

core/src/main/java/org/jruby/RubyComparable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ private static IRubyObject callCmpMethod(ThreadContext context, IRubyObject recv
145145

146146
return RubyBoolean.newBoolean(runtime, cmpint(context, result, recv, other) == 0);
147147
} catch (RaiseException e) {
148-
cmpFailed(context);
149148
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
149+
cmpFailed(context);
150150
// clear error info resulting from failure to compare (JRUBY-3292)
151151
runtime.getGlobalVariables().set("$!", savedError);
152152
return returnValueOnError;

core/src/main/java/org/jruby/RubyNumeric.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,18 @@ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boo
473473
try {
474474
result = coerceBody(context, other);
475475
} catch (RaiseException e) {
476-
RubyWarnings warnings = context.runtime.getWarnings();
477-
warnings.warn("Numerical comparison operators will no more rescue exceptions of #coerce");
478-
warnings.warn("in the next release. Return nil in #coerce if the coercion is impossible.");
479-
if (err) {
480-
coerceFailed(context, other);
476+
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
477+
RubyWarnings warnings = context.runtime.getWarnings();
478+
warnings.warn("Numerical comparison operators will no more rescue exceptions of #coerce");
479+
warnings.warn("in the next release. Return nil in #coerce if the coercion is impossible.");
480+
if (err) {
481+
coerceFailed(context, other);
482+
}
483+
context.runtime.getGlobalVariables().set("$!", savedError); // Restore $!
484+
return null;
485+
} else {
486+
throw e;
481487
}
482-
context.runtime.getGlobalVariables().set("$!", savedError); // Restore $!
483-
return null;
484488
}
485489

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

0 commit comments

Comments
 (0)