Issue #17427 has been reported by amcaplan (Ariel Caplan).

----------------------------------------
Bug #17427: Hash getting multiple identical keys
https://bugs.ruby-lang.org/issues/17427

* Author: amcaplan (Ariel Caplan)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I have a situation where a hash (contained within a Set) seems to get duplicate keys. I've had some difficulty reproducing the issue in a minimal fashion, but I have a 175-ish-line program that runs it. (Just for context, if you want to know what's doing what, it's meant to solve https://adventofcode.com/2020/day/22 part 2.)

When I run it on my machine, it will quickly error out with something like:

``` ruby
[[26, 22, 44, 16, 31, 19, 30, 10, 40, 47, 21, 48, 45], [4, 24, 1, 7, 36, 29, 38, 33, 3, 13, 11, 17, 39]]
[[26, 22, 44, 16, 31, 19, 30, 10, 40, 47, 21, 48, 45], [4, 24, 1, 7, 36, 29, 38, 33, 3, 13, 11, 17, 39]]
aoc22.rb:37:in `play_against!': #<Set: {[[26, 22, 44, 16, 31, 19, 30, 10, 40, 47, 21, 48, 45], [4, 24, 1, 7, 36, 29, 38, 33, 3, 13, 11, 17, 39]], [[26, 22, 44, 16, 31, 19, 30, 10, 40, 47, 21, 48, 45], [4, 24, 1, 7, 36, 29, 38, 33, 3, 13, 11, 17, 39]]}> (RuntimeError)
	from aoc22.rb:88:in `compete!'
	from aoc22.rb:39:in `each'
	from aoc22.rb:39:in `inject'
	from aoc22.rb:39:in `play_against!'
	from aoc22.rb:174:in `each'
	from aoc22.rb:174:in `inject'
	from aoc22.rb:174:in `<main>'
```

showing that the Set somehow contains 2 identical items.

By the way, if you replace `[stack, other_deck.stack]` with `[stack, other_deck.stack].hash` on lines 32 and 40, the program executes successfully.

I've been able to reproduce on multiple versions of Ruby up to 2.7.0. I'd test on a Ruby 3 preview also, but I've had trouble installing it, sorry.

---Files--------------------------------
aoc22.rb (2.51 KB)


-- 
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>