Skip to content

Commit

Permalink
merge revision(s) b176315: [Backport #20324]
Browse files Browse the repository at this point in the history
	[Bug #20324] Uncomparable ranges are not overlapping
  • Loading branch information
nurse committed Mar 22, 2024
1 parent eb7cb16 commit a920651
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions range.c
Original file line number Diff line number Diff line change
Expand Up @@ -2373,8 +2373,16 @@ range_overlap(VALUE range, VALUE other)
if (empty_region_p(self_beg, other_end, other_excl)) return Qfalse;
if (empty_region_p(other_beg, self_end, self_excl)) return Qfalse;

/* if both begin values are equal, no more comparisons needed */
if (rb_equal(self_beg, other_beg)) return Qtrue;
if (!NIL_P(self_beg) && !NIL_P(other_beg)) {
VALUE cmp = rb_funcall(self_beg, id_cmp, 1, other_beg);
if (NIL_P(cmp)) return Qfalse;
/* 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)) {
VALUE cmp = rb_funcall(self_end, id_cmp, 1, other_end);
return RBOOL(!NIL_P(cmp));
}

if (empty_region_p(self_beg, self_end, self_excl)) return Qfalse;
if (empty_region_p(other_beg, other_end, other_excl)) return Qfalse;
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,8 @@ def test_overlap?
assert_operator(0.., :overlap?, 1..)

assert_not_operator((1..3), :overlap?, ('a'..'d'))
assert_not_operator((1..), :overlap?, ('a'..))
assert_not_operator((..1), :overlap?, (..'a'))

assert_raise(TypeError) { (0..).overlap?(1) }
assert_raise(TypeError) { (0..).overlap?(nil) }
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 19
#define RUBY_PATCHLEVEL 20

#include "ruby/version.h"
#include "ruby/internal/abi.h"
Expand Down

0 comments on commit a920651

Please sign in to comment.