Skip to content

Commit b5cdbad

Browse files
jeromeplnobu
authored andcommitted
[Bug #21185] Fix Range#overlap? with infinite range
Infinite ranges, i.e. unbounded ranges, should overlap with any other range which wasn't the case in the following example: (0..3).overlap?(nil..nil)
1 parent 3e04f7b commit b5cdbad

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

range.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ range_overlap(VALUE range, VALUE other)
25612561
/* if both begin values are equal, no more comparisons needed */
25622562
if (rb_cmpint(cmp, self_beg, other_beg) == 0) return Qtrue;
25632563
}
2564-
else if (NIL_P(self_beg) && !NIL_P(self_end) && NIL_P(other_beg)) {
2564+
else if (NIL_P(self_beg) && !NIL_P(self_end) && NIL_P(other_beg) && !NIL_P(other_end)) {
25652565
VALUE cmp = rb_funcall(self_end, id_cmp, 1, other_end);
25662566
return RBOOL(!NIL_P(cmp));
25672567
}

test/ruby/test_range.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,7 @@ def test_overlap?
15131513
assert_operator((nil..nil), :overlap?, (3..))
15141514
assert_operator((nil...nil), :overlap?, (nil..))
15151515
assert_operator((nil..nil), :overlap?, (..3))
1516+
assert_operator((..3), :overlap?, (nil..nil))
15161517

15171518
assert_raise(TypeError) { (1..3).overlap?(1) }
15181519

0 commit comments

Comments
 (0)