Repository navigation
Conversation
`==`/`isequal` compare `OffsetInteger`s by value, also across different offsets and against plain integers (via `promote_rule`), but `hash` mixed the raw stored integer with the offset. So `isequal(ZeroIndex(123), OneIndex(123))` was `true` while their hashes differed, which breaks `Dict`/`Set` lookups. Hash the value instead, like the integer it equals. Fixes JuliaGeometry#288 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #288
==/isequalcompareOffsetIntegers by value, also across different offsets and against plain integers (throughpromote_rule).hashinstead mixed the raw stored integer with the offset, so equal values could hash differently:This breaks hashed collections:
Dict(ZeroIndex(10) => :a)[OneIndex(10)]throws aKeyError, andSet{Any}((ZeroIndex(1), OneIndex(1), 1))has 3 elements.The method is now
hash(value(o), h), so anOffsetIntegerhashes like the integer it is equal to. It is a one-line change insrc/offsetintegers.jl.One side effect: since the hashes now match, a
DictorSetholding anOffsetIntegerand an equalFloat64has to callisequalon the pair, and that throws, becauseOneIndex(1) == 1.0already throws on master ("promotion of types OneIndex{Int64} and Float64 failed to change any arguments"). Before,Set{Any}(Any[OneIndex(1), 1.0])silently kept both elements.Boolbehaves the same until #289 is merged. Comparison with floats is a separate problem, so I left it out of this PR.Tests: a new block in the
Offsetintegerstestset checksisequal(a, b)andhash(a) == hash(b)(with and without a seed) for different offsets, element types (Int,GLIndex,Int8vsUInt8) and plain integers, plusSetandDictlookups. On master it gives 14 failures and 1 error; with the change it passes on Julia 1.13.4 and 1.10.14. The fullPkg.test()passes locally on Julia 1.13.4 (1351 pass, plus the 2 existing@test_broken).This doesn't touch the lines changed by #289 or #290. I checked that it applies cleanly on top of both and that the full test suite still passes there.
This PR was written with an AI assistant (Claude Code).
This merges cleanly with #289 and #290. If you'd rather fold the
hashchange into your series, feel free to close this one.🤖 Generated with Claude Code