Skip to content

Hashcodes of nested case classes do not take outer into account #9748

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

Open
odersky opened this issue Sep 8, 2020 · 1 comment
Open

Hashcodes of nested case classes do not take outer into account #9748

odersky opened this issue Sep 8, 2020 · 1 comment
Assignees

Comments

@odersky
Copy link
Contributor

odersky commented Sep 8, 2020

Minimized example

class A {
  case class B()
}

Output

If we compile with -Xprint:typer we get this line in the definitions of B:

      override def hashCode(): Int = scala.runtime.ScalaRunTime._hashCode(this)

The hashcode does not account for the hashcode of the outer object, even though equals does compare outer objects. This leads to bad hash functions if inner case classes are used as keys in maps.

odersky added a commit to dotty-staging/dotty that referenced this issue Sep 8, 2020
@odersky
Copy link
Contributor Author

odersky commented Sep 8, 2020

Scala-2 has the same problem.

odersky added a commit to dotty-staging/dotty that referenced this issue Sep 8, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue Sep 14, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue Sep 24, 2020
@odersky odersky self-assigned this Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants