Skip to content

Commit 7484e61

Browse files
adienesclaude
andcommitted
Fix incorrect one-arg Base.hash method
Generated as part of an ecosystem-wide audit for one-arg hash methods. The `hash(arg::LowerOrUpperIndex)` method only defined a one-arg `Base.hash`, which means the two-arg fallback `hash(x, h::UInt)` uses `objectid`-based hashing instead. This can cause correctness issues (equal objects hashing differently) and performance problems (excessive invalidation). With Julia 1.13+, the default hash seed is changing from `zero(UInt)` to a random value, which will make the one-arg method produce different results on each session. Fix by converting to a proper two-arg method that chains the seed `h` through the hash computation. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d5a96a8 commit 7484e61

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

src/index.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ function same_to(old::Upper, letter::Letter)
4242
return Upper(letter)
4343
end
4444

45-
function hash(arg::LowerOrUpperIndex)
46-
h::UInt = 0
47-
45+
function hash(arg::LowerOrUpperIndex, h::UInt)
46+
val::UInt = 0
4847
if typeof(arg) == Lower
49-
h |= 1
48+
val |= 1
5049
end
51-
52-
h |= arg.letter << 1
53-
54-
h
50+
val |= arg.letter << 1
51+
hash(val, h)
5552
end

0 commit comments

Comments
 (0)