Project

General

Profile

Bug #17034 ยป range-max-beginless.patch

citizen428 (Michael Kohl), 07/17/2020 04:25 PM

View differences:

range.c
rb_raise(rb_eRangeError, "cannot get the maximum of endless range");
}
VALUE b = RANGE_BEG(range);
if (rb_block_given_p() || (EXCL(range) && !nm) || argc) {
if (NIL_P(RANGE_BEG(range))) {
if (NIL_P(b)) {
rb_raise(rb_eRangeError, "cannot get the maximum of beginless range with custom comparison method");
}
return rb_call_super(argc, argv);
}
else {
struct cmp_opt_data cmp_opt = { 0, 0 };
VALUE b = RANGE_BEG(range);
int c = OPTIMIZED_CMP(b, e, cmp_opt);
int c = NIL_P(b) ? -1 : OPTIMIZED_CMP(b, e, cmp_opt);
if (c > 0)
return Qnil;
test/ruby/test_range.rb
assert_raise(RangeError) { (1...).max(3) }
assert_raise(RangeError) { (..0).min {|a, b| a <=> b } }
assert_equal(2, (..2).max)
assert_raise(TypeError, (...2).max)
assert_raise(TypeError, (...2.0).max)
end
def test_minmax
    (1-1/1)