Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModularBigInteger does not override hashCode (but overrides equals) #291

Closed
iaik-jheher opened this issue May 23, 2024 · 0 comments · Fixed by #294
Closed

ModularBigInteger does not override hashCode (but overrides equals) #291

iaik-jheher opened this issue May 23, 2024 · 0 comments · Fixed by #294

Comments

@iaik-jheher
Copy link
Contributor

iaik-jheher commented May 23, 2024

ModularBigInteger overrides equals, but does not override hashCode.
Thus, distinct objects that compare equally (using structural equality) will not have the same hashCode.

This violates the general hashCode contract.

MWE:

val creator = ModularBigInteger.creatorForModulo(7)
val a = creator.fromInt(6)
val b = creator.fromInt(6)

if (a == b) {
  require(a.hashCode() == b.hashCode())
}
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 a pull request may close this issue.

1 participant