Issue #14263 has been updated by styrmis (Stefan Magnuson).

File array-eql-by-hash.patch added
File object-eql-documentation-tweak.patch added

Attached are two patches:

- One which uses hash comparison for both the optimised "small" array branch and the default implementation of the `Array` set operations (essentially restoring the behaviour of Ruby < 2.5)
- Another which adds a warning to the documentation for `Array#eql?`, stating that the link between hash equality and `eql?` must not be broken in subclasses

As the behaviour being relied upon in Ruby < 2.5 is not well defined (`#eql?` has been modified to not take the hashes of compared objects into account), then perhaps updating the documentation is the better approach.

If backwards compatibility of the (undefined) behaviour is to be maintained, then I believe the patch to `Array` achieves this, though is perhaps of limited value.

All feedback is of course very welcome!

----------------------------------------
Bug #14263: Array Intersection does not seem to use hash
https://bugs.ruby-lang.org/issues/14263#change-71212

* Author: gkellogg (Gregg Kellogg)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.5.0
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
According to the documentation for Array#&, comparison is done using hash and eql? However, this does not seem to be the case in 2.5.0.

If two instances are .eql? but their hashes are not, an array & should be empty:

~~~ ruby
([Var.new('a')] & [Var.new('b')]).empty?

~~~

This test works in 2.4.2 (and all earlier versions), but fails in 2.5.0. See attached script.

---Files--------------------------------
array_intersection.rb (535 Bytes)
test-14264.rb (956 Bytes)
array-eql-by-hash.patch (2.09 KB)
object-eql-documentation-tweak.patch (825 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>