From: "smokinggun (John Weir)" <noreply@...>
Date: 2022-01-11T01:08:41+00:00
Subject: [ruby-core:107033] [Ruby master Bug#18470] Union of two identical sets produces a set with duplicate members

Issue #18470 has been updated by smokinggun (John Weir).


> The main problem is that `Set` doesn't expose a `rehash` method, so there's not really any way to workaround it. Maybe it should?

The rehash works.  Should `add` also have a rehash?

```ruby
C = Struct.new :id
a = Set.new
f = C.new
a << f
f.id = 1
a << f
# => #<Set: {#<struct C id=1>, #<struct C id=1>}>
```

----------------------------------------
Bug #18470: Union of two identical sets produces a set with duplicate members
https://bugs.ruby-lang.org/issues/18470#change-95864

* Author: smokinggun (John Weir)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-linux]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
We came across an issue where the union of two identical sets produced a non uniq Set.

We noticed this when upgrading from 2.7.1 to 3.1

See the attached test, the last assertion fails

``` ruby
C = Struct.new :id
a = Set.new
b = Set.new
f = C.new
a << f
f.id = 1
b << f
a + b
# => #<Set: {#<struct C id=1>, #<struct C id=1>}>
b + a
# => #<Set: {#<struct C id=1>}>

(a + b).uniq
=> [#<struct C id=1>]
```


---Files--------------------------------
set_test.rb (348 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>