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

Overriding productPrefix breaks case class hash code #13033

Open
lrytz opened this issue Sep 10, 2024 · 1 comment · May be fixed by scala/scala#10859
Open

Overriding productPrefix breaks case class hash code #13033

lrytz opened this issue Sep 10, 2024 · 1 comment · May be fixed by scala/scala#10859
Assignees
Labels
Milestone

Comments

@lrytz
Copy link
Member

lrytz commented Sep 10, 2024

scala> abstract case class C1(a: Int)
     | class C2(a: Int) extends C1(a) { override def productPrefix = "C2" }
     | class C3(a: Int) extends C1(a) { override def productPrefix = "C3" }

scala> val s = collection.mutable.HashSet.empty[C1]

scala> s.addOne(new C2(1))

scala> val c3 = new C3(1)

scala> s.find(_ == c3)
val res1: Option[C1] = Some(C2(1))

scala> s.contains(c3)
val res2: Boolean = false
@lrytz lrytz self-assigned this Sep 10, 2024
@som-snytt
Copy link

Alternatively, canEqual is broken and should include productPrefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants