diff --git a/array.c b/array.c index 6f14b99..63f5168 100644 --- a/array.c +++ b/array.c @@ -3532,19 +3532,17 @@ recursive_equal(VALUE ary1, VALUE ary2, int recur) len1 = RARRAY_LEN(ary1); for (i = 0; i < len1; i++) { - if (*p1 != *p2) { - if (rb_equal(*p1, *p2)) { - len1 = RARRAY_LEN(ary1); - if (len1 != RARRAY_LEN(ary2)) - return Qfalse; - if (len1 < i) - return Qtrue; - p1 = RARRAY_PTR(ary1) + i; - p2 = RARRAY_PTR(ary2) + i; - } - else { + if (rb_equal(*p1, *p2)) { + len1 = RARRAY_LEN(ary1); + if (len1 != RARRAY_LEN(ary2)) return Qfalse; - } + if (len1 < i) + return Qtrue; + p1 = RARRAY_PTR(ary1) + i; + p2 = RARRAY_PTR(ary2) + i; + } + else { + return Qfalse; } p1++; p2++; diff --git a/object.c b/object.c index 660be57..c664a73 100644 --- a/object.c +++ b/object.c @@ -51,10 +51,7 @@ static ID id_const_missing; VALUE rb_equal(VALUE obj1, VALUE obj2) { - VALUE result; - - if (obj1 == obj2) return Qtrue; - result = rb_funcall(obj1, id_eq, 1, obj2); + VALUE result = rb_funcall(obj1, id_eq, 1, obj2); if (RTEST(result)) return Qtrue; return Qfalse; } diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 6c7f920..fd26355 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2275,4 +2275,14 @@ class TestArray < Test::Unit::TestCase a = [0, 4, 7, 10, 12] assert_equal(nil, a.bsearch {|x| "foo" }) # undefined behavior end + + def test_array_equal_with_identical_but_nonequal_objects # [ruby-core:51328] + refute [Float::NAN] == [Float::NAN] + + o = Object.new + def o.==(other) + false + end + refute [o] == [o] + end end