Project

General

Profile

Actions

Bug #20307

closed

`Hash#update` from compare_by_identity hash can have unfrozen string keys

Added by nobu (Nobuyoshi Nakada) 3 months ago. Updated 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:116965]

Description

I don't think this behavior is expected.

i = Hash.new.compare_by_identity
k = "a"
i[k] = 0
h = {}.update(i)
p h.compare_by_identity?  # => false
p h["a"]                  # => 0

k.upcase!
# `k` is still in `h`.
p h.keys.include?(k)      # => true

# but not found.
p((h.fetch(k) rescue $!)) # => #<KeyError: key not found: "A">
h["A"] = 1  
p h                       # => {"A"=>0, "A"=>1}

I expect h to still have "a"=>0 entry.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0