Project

General

Profile

Bug #7768 ยป array-uniq-subclass-instance.patch

jeremyevans0 (Jeremy Evans), 07/15/2019 09:07 PM

View differences:

array.c
{
VALUE hash, uniq;
if (RARRAY_LEN(ary) <= 1)
return rb_ary_dup(ary);
if (rb_block_given_p()) {
if (RARRAY_LEN(ary) <= 1) {
hash = 0;
uniq = rb_ary_dup(ary);
}
else if (rb_block_given_p()) {
hash = ary_make_hash_by(ary);
uniq = rb_hash_values(hash);
}
......
uniq = rb_hash_values(hash);
}
RBASIC_SET_CLASS(uniq, rb_obj_class(ary));
ary_recycle_hash(hash);
if (hash) {
ary_recycle_hash(hash);
}
return uniq;
}
test/ruby/test_array.rb
ary = [bug9340, bug9340.dup, bug9340.dup]
assert_equal 1, ary.uniq.size
assert_same bug9340, ary.uniq[0]
sc = Class.new(@cls)
a = sc[]
b = a.dup
assert_instance_of(sc, a.uniq)
assert_equal(sc[], a.uniq)
assert_equal(b, a)
a = sc[1]
b = a.dup
assert_instance_of(sc, a.uniq)
assert_equal(sc[1], a.uniq)
assert_equal(b, a)
a = sc[1, 1]
b = a.dup
assert_instance_of(sc, a.uniq)
assert_equal(sc[1], a.uniq)
assert_equal(b, a)
a = sc[1, 1]
b = a.dup
assert_instance_of(sc, a.uniq{|x| x})
assert_equal(sc[1], a.uniq{|x| x})
assert_equal(b, a)
end
def test_uniq_with_block
    (1-1/1)