Actions
Bug #22013
closedArray#| deduplication via eql? breaks when total element count exceeds ~16
Bug #22013:
Array#| deduplication via eql? breaks when total element count exceeds ~16
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [arm64-darwin24]
Tags:
Description
Problem description¶
The documentation for Array#| states:
Returns the union of self and other_array; duplicates are removed; order is preserved; items are compared using
eql?
However, when the total number of elements across both arrays exceeds ~16, deduplication via eql? stops working and duplicates are included in the result.
Reproducible script¶
class Item
attr_reader :id, :pos
def initialize(id, pos:)
@id = id
@pos = pos
end
def inspect
"item-#{id}-#{pos}"
end
def eql?(other)
id == other.id
end
end
items1 = [Item.new(1, pos: 1)]
items2 = [Item.new(1, pos: 2)] # same id — should be treated as duplicate by eql?
puts (items1 | items2 ).inspect # 2 total elements
puts (items1 * 8 | items2 * 8 ).inspect # 16 total elements
puts (items1 * 15 | items2 * 1 ).inspect # 16 total elements
puts (items1 * 9 | items2 * 8 ).inspect # 17 total elements
Actual result¶
[item-1-1]
[item-1-1]
[item-1-1]
[item-1-1, item-1-2]
Expected result¶
All four lines should return [item-1-1], since eql? returns true for both items and the documentation makes no mention of any size-dependent behavior.
The last line incorrectly returns two elements. The only change is the total element count crossing ~16 — the objects and eql? implementation are identical.
Actions