Skip to content

Commit

Permalink
Warn about mutating keys in Dict docstring. (JuliaLang#51171)
Browse files Browse the repository at this point in the history
Be clear in the `Dict` docstring that it's not in general safe to mutate
keys. Cf.
https://discourse.julialang.org/t/unable-to-access-value-in-dict-via-known-keys/103434.
  • Loading branch information
GunnarFarneback authored Sep 8, 2023
1 parent de297fa commit 5e85876
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ Dict{String, Int64} with 2 entries:
"B" => 2
"A" => 1
```
!!! warning
Keys are allowed to be mutable, but if you do mutate stored
keys, the hash table may become internally inconsistent, in which case
the `Dict` will not work properly. [`IdDict`](@ref) can be an
alternative if you need to mutate keys.
"""
mutable struct Dict{K,V} <: AbstractDict{K,V}
# Metadata: empty => 0x00, removed => 0x7f, full => 0b1[7 most significant hash bits]
Expand Down

0 comments on commit 5e85876

Please sign in to comment.