Skip to content

Fix incorrect one-arg Base.hash method#15

Open
adienes wants to merge 1 commit intoasterycs:trunkfrom
adienes:fix-hash-one-arg
Open

Fix incorrect one-arg Base.hash method#15
adienes wants to merge 1 commit intoasterycs:trunkfrom
adienes:fix-hash-one-arg

Conversation

@adienes
Copy link
Copy Markdown

@adienes adienes commented Mar 19, 2026

Generated as part of an ecosystem-wide audit for one-arg hash methods.

Summary

The hash(arg::LowerOrUpperIndex) method in src/index.jl only defines a one-arg Base.hash. This means the two-arg fallback hash(x, h::UInt) uses objectid-based hashing instead, which can cause:

  • Correctness bugs: equal objects may hash differently when used in containers like Dict or Set
  • Performance issues: excessive method invalidation across the ecosystem
  • Julia 1.13+ breakage: the default hash seed is changing from zero(UInt) to a random value, so the one-arg method will produce different results each session

Fix

Convert to a proper two-arg hash(arg::LowerOrUpperIndex, h::UInt) that chains the seed through the computation.

Test plan

  • Verified the fix compiles and the hash contract is maintained

This PR was generated with the assistance of generative AI.

Co-Authored-By: Claude noreply@anthropic.com

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>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.74%. Comparing base (d5a96a8) to head (7484e61).
⚠️ Report is 1 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk      #15   +/-   ##
=======================================
  Coverage   93.74%   93.74%           
=======================================
  Files           9        9           
  Lines        1630     1630           
=======================================
  Hits         1528     1528           
  Misses        102      102           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant