Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ecf16d2d5d19
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ec40e444476a
Choose a head ref
  • 4 commits
  • 3 files changed
  • 2 contributors

Commits on Jan 31, 2018

  1. Copy the full SHA
    28100b3 View commit details
  2. No longer rescue exceptions of #coerce for Numerical comparison opera…

    …tors (< ,<=, >=, >)
    
    For more information, please see feature #7688.
    nomadium committed Jan 31, 2018
    Copy the full SHA
    b729677 View commit details
  3. No longer rescue exceptions from Integer#step when given a step value…

    … which cannot be compared with #> to 0
    
    For more information, please see feature #7688.
    nomadium committed Jan 31, 2018
    Copy the full SHA
    e29816f View commit details

Commits on Feb 1, 2018

  1. Merge pull request #5025 from nomadium/no-longer-hide-exceptions-from…

    …-coerce-method
    
    No longer hide exceptions from coerce method
    enebo authored Feb 1, 2018
    Copy the full SHA
    ec40e44 View commit details
Showing with 12 additions and 42 deletions.
  1. +3 −33 core/src/main/java/org/jruby/RubyNumeric.java
  2. +1 −1 test/mri/ruby/test_float.rb
  3. +8 −8 test/mri/ruby/test_numeric.rb
36 changes: 3 additions & 33 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -474,35 +474,14 @@ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boo
}
final IRubyObject $ex = context.getErrorInfo();
final IRubyObject result;
try {
result = coerceBody(context, other);
}
catch (RaiseException e) { // e.g. NoMethodError: undefined method `coerce'
if (context.runtime.getStandardError().isInstance( e.getException() )) {
context.setErrorInfo($ex); // restore $!
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);
}
return null;
}
throw e;
}

result = coerceBody(context, other);
return coerceResult(context.runtime, result, err);
}

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.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.");
}
if (err || !result.isNil()) throw runtime.newTypeError("coerce must return [x, y]");
return null;
}

@@ -974,16 +953,7 @@ else if (num instanceof RubyBignum) {
}
}
IRubyObject r = UNDEF;
try {
context.setExceptionRequiresBacktrace(false);
r = stepCompareWithZero(context, num);
} catch (RaiseException re) {
} finally {
context.setExceptionRequiresBacktrace(true);
}
if (r == UNDEF) {
coerceFailed(context, num);
}
r = stepCompareWithZero(context, num);
return !r.isTrue();
}

2 changes: 1 addition & 1 deletion test/mri/ruby/test_float.rb
Original file line number Diff line number Diff line change
@@ -782,7 +782,7 @@ def test_invalid_str
end

def test_num2dbl
assert_raise(TypeError) do
assert_raise(ArgumentError, "comparison of String with 0 failed") do
1.0.step(2.0, "0.5") {}
end
assert_raise(TypeError) do
16 changes: 8 additions & 8 deletions test/mri/ruby/test_numeric.rb
Original file line number Diff line number Diff line change
@@ -54,18 +54,16 @@ def coerce(x); [x, 1]; end

bug7688 = '[ruby-core:51389] [Bug #7688]'
a = Class.new(Numeric) do
def coerce(x); raise StandardError; end
def coerce(x); raise StandardError, "my error"; end
end.new
assert_raise_with_message(TypeError, /can't be coerced into /) { 1 + a }
warn = /will no more rescue exceptions of #coerce.+ in the next release/m
assert_warn(warn, bug7688) { assert_raise(ArgumentError) { 1 < a } }
assert_raise_with_message(StandardError, "my error") { 1 + a }
assert_raise_with_message(StandardError, "my error") { 1 < a }

a = Class.new(Numeric) do
def coerce(x); :bad_return_value; end
end.new
assert_raise_with_message(TypeError, "coerce must return [x, y]") { 1 + a }
warn = /Bad return value for #coerce.+next release will raise an error/m
assert_warn(warn, bug7688) { assert_raise(ArgumentError) { 1 < a } }
assert_raise_with_message(TypeError, "coerce must return [x, y]") { 1 < a }
end

def test_singleton_method
@@ -252,13 +250,15 @@ def assert_step(expected, (from, *args), inf: false)
end

def test_step
# RbConfig::LIMITS is something new in MRI 2.5.0, we don't have it yet
# bignum = RbConfig::LIMITS['FIXNUM_MAX'] + 1
bignum = Integer::FIXNUM_MAX + 1
assert_raise(ArgumentError) { 1.step(10, 1, 0) { } }
assert_raise(ArgumentError) { 1.step(10, 1, 0).size }
assert_raise(ArgumentError) { 1.step(10, 0) { } }
assert_raise(ArgumentError) { 1.step(10, 0).size }
assert_raise(TypeError) { 1.step(10, "1") { } }
assert_raise(TypeError) { 1.step(10, "1").size }
assert_raise(ArgumentError) { 1.step(10, "1") { } }
assert_raise(ArgumentError) { 1.step(10, "1").size }
assert_raise(TypeError) { 1.step(10, nil) { } }
assert_raise(TypeError) { 1.step(10, nil).size }
assert_nothing_raised { 1.step(by: 0, to: nil) }