Skip to content

Commit 2449377

Browse files
committed
[Bug #20725] Should not call compare on nil-endpoint
It means unbounded, always inclusive of other ranges.
1 parent 0f3dc2f commit 2449377

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
@@ -2477,7 +2477,7 @@ range_overlap(VALUE range, VALUE other)
24772477
/* if both begin values are equal, no more comparisons needed */
24782478
if (rb_cmpint(cmp, self_beg, other_beg) == 0) return Qtrue;
24792479
}
2480-
else if (NIL_P(self_beg) && NIL_P(other_beg)) {
2480+
else if (NIL_P(self_beg) && !NIL_P(self_end) && NIL_P(other_beg)) {
24812481
VALUE cmp = rb_funcall(self_end, id_cmp, 1, other_end);
24822482
return RBOOL(!NIL_P(cmp));
24832483
}

test/ruby/test_range.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,7 @@ def test_overlap?
14711471
assert_operator((..3), :overlap?, (3..))
14721472
assert_operator((nil..nil), :overlap?, (3..))
14731473
assert_operator((nil...nil), :overlap?, (nil..))
1474+
assert_operator((nil..nil), :overlap?, (..3))
14741475

14751476
assert_raise(TypeError) { (1..3).overlap?(1) }
14761477

0 commit comments

Comments
 (0)