summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-09-13 10:50:38 +0900
committerNobuyoshi Nakada <[email protected]>2024-09-13 18:23:28 +0900
commit24493779b79bb57fd2e71bf6e0ababe95448a9d6 (patch)
tree5155b378019571c120785e540b65d9926df01fa7
parent0f3dc2f958bd1447cc459bc4a4f39071a6a07a9c (diff)
[Bug #20725] Should not call compare on `nil`-endpoint
It means unbounded, always inclusive of other ranges.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11609
-rw-r--r--range.c2
-rw-r--r--test/ruby/test_range.rb1
2 files changed, 2 insertions, 1 deletions
diff --git a/range.c b/range.c
index e8a35c22cc..e4e73bd85d 100644
--- a/range.c
+++ b/range.c
@@ -2477,7 +2477,7 @@ range_overlap(VALUE range, VALUE other)
/* if both begin values are equal, no more comparisons needed */
if (rb_cmpint(cmp, self_beg, other_beg) == 0) return Qtrue;
}
- else if (NIL_P(self_beg) && NIL_P(other_beg)) {
+ else if (NIL_P(self_beg) && !NIL_P(self_end) && NIL_P(other_beg)) {
VALUE cmp = rb_funcall(self_end, id_cmp, 1, other_end);
return RBOOL(!NIL_P(cmp));
}
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 842be77ab3..e0c1d20bd2 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -1471,6 +1471,7 @@ class TestRange < Test::Unit::TestCase
assert_operator((..3), :overlap?, (3..))
assert_operator((nil..nil), :overlap?, (3..))
assert_operator((nil...nil), :overlap?, (nil..))
+ assert_operator((nil..nil), :overlap?, (..3))
assert_raise(TypeError) { (1..3).overlap?(1) }