Skip to content

Commit 71a6fc9

Browse files
authored
add admonition to hash docstring about default seed arguments (#59781)
1 parent db003be commit 71a6fc9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

base/hashing.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Typically, any type that implements `hash` should also implement its own [`==`](
2121
2222
The hash value may change when a new Julia process is started.
2323
24+
!!! warning
25+
When implementing the 2-argument form, the second argument `h` should _not_ be given a
26+
default value such `h = UInt(0)` as this will implicitly create a 1-argument method that
27+
is more specific than the fallback (see [Note on Optional and keyword Arguments](@ref)),
28+
but potentially with the wrong seed, causing hash inconsistencies.
29+
2430
```jldoctest; filter = r"0x[0-9a-f]{16}"
2531
julia> a = hash(10)
2632
0x759d18cc5346a65f

0 commit comments

Comments
 (0)