From b5cdbadeeddd2b8e834b9d5565c13fcc43f3e684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parent-L=C3=A9vesque?= Date: Sat, 15 Mar 2025 15:05:50 -0400 Subject: [PATCH] [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) --- range.c | 2 +- test/ruby/test_range.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/range.c b/range.c index 90d9ae2ab3..50a35d4964 100644 --- a/range.c +++ b/range.c @@ -2561,7 +2561,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(self_end) && NIL_P(other_beg)) { + else if (NIL_P(self_beg) && !NIL_P(self_end) && NIL_P(other_beg) && !NIL_P(other_end)) { 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 bc73de78d3..f875c0ab40 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -1513,6 +1513,7 @@ class TestRange < Test::Unit::TestCase assert_operator((nil..nil), :overlap?, (3..)) assert_operator((nil...nil), :overlap?, (nil..)) assert_operator((nil..nil), :overlap?, (..3)) + assert_operator((..3), :overlap?, (nil..nil)) assert_raise(TypeError) { (1..3).overlap?(1) }