Skip to content

case class equals doesn't check canEqual #10527

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

Closed
lrytz opened this issue Nov 27, 2020 · 0 comments
Closed

case class equals doesn't check canEqual #10527

lrytz opened this issue Nov 27, 2020 · 0 comments
Assignees

Comments

@lrytz
Copy link
Member

lrytz commented Nov 27, 2020

scala> case class C(x: Int)
// defined case class C

scala> class CC(x: Int) extends C(x) { override def canEqual(o: Any) = o.isInstanceOf[CC] }
// defined class CC

scala> C(1) == new CC(1)
val res0: Boolean = true

In Scala 2 the result is false.

The generated equals in Scala 3:

    override def equals(x$0: Any): Boolean =
      this.eq(x$0.$asInstanceOf$[Object]).||(
        x$0 match
          {
            case x$0 @ _:C @unchecked => this.x.==(x$0.x)
            case _ => false
          }
      )

while in Scala 2

    override <synthetic> def equals(x$1: Any): Boolean = C.this.eq(x$1.asInstanceOf[Object]).||(x$1 match {
  case (_: C) => true
  case _ => false
}.&&({
      <synthetic> val C$1: C = x$1.asInstanceOf[C];
      C.this.x.==(C$1.x).&&(C$1.canEqual(C.this))
    }))
@odersky odersky self-assigned this Dec 2, 2020
bishabosha added a commit that referenced this issue Dec 2, 2020
Fix #10527: Generate `canEqual` test for case class equals
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