i=Hash.new.compare_by_identityk="a"i[k]=0h={}.update(i)ph.compare_by_identity?# => falseph["a"]# => 0k.upcase!# `k` is still in `h`.ph.keys.include?(k)# => true# but not found.p((h.fetch(k)rescue$!))# => #<KeyError: key not found: "A">h["A"]=1ph# => {"A"=>0, "A"=>1}
When a key is clobbered like that due to a rehash, maybe there should be a warning or an error? It seems to me a pretty clear symptom of a bug, either in the ruby code or in the interpreter itself.
I'd expect cache[key] to return 1, with what I understand of your patch, it wouldn't anymore.
Mutable hash keys aren't a new thing, it's only that regular hash have this special behavior for strings to keep a frozen copy of the string key, but they don't do that for any other type.
I don't see why identity hashes would need to copy this behavior.