crystal icon indicating copy to clipboard operation
crystal copied to clipboard

`Hash#rehash` should remove duplicate elements

Open HertzDevil opened this issue 5 months ago • 0 comments

If a hash uses mutable keys and #compare_by_identity is not called, the keys might eventually compare equal due to external modifications. In this case Hash#rehash removes duplicate keys in Ruby:

a = [1]
b = [2]
c = {a => 3, b => 4}
a[0] = 2
c.rehash
c # => {[2] => 4}

The same code produces {[2] => 3, [2] => 4} in Crystal even after the #rehash call.

HertzDevil avatar Oct 27 '25 14:10 HertzDevil