Skip to content

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

Open
@odersky

Description

@odersky

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions