-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Strict equality CanEqual derivation fails for classes in which type argument is not used for equality #14544
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
Comments
I cannot reproduce it: ➜ scala
Welcome to Scala 3.1.1 (17.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> case class MyClass[A](value: String)(val a: A) derives CanEqual
// defined case class MyClass
scala> class Something {}
// defined class Something
scala> val a = MyClass[Something]("some")(new Something())
val a: MyClass[Something] = MyClass(some)
scala> val b = MyClass[Something]("some")(new Something())
val b: MyClass[Something] = MyClass(some)
scala> println(a == b)
true |
@spameggo you need to enable strict quality via: import scala.language.strictEquality |
It seems that the code above is correctly complaining as there is no instance of given derived$CanEqual[L, R](implicit x$0: CanEqual[L, R]): CanEqual[MyClass[L], MyClass[R]] = CanEqual.derived Note that under strict equality the comparison given CanEqual[Something, Something] = CanEqual.derived or derive it on class Something derives CanEqual {} |
@odersky should derive generate - given derived$CanEqual[L, R](implicit x$0: CanEqual[L, R]): CanEqual[MyClass[L], MyClass[R]] = CanEqual.derived
+ given derived$CanEqual[L, R](using x$0: CanEqual[L, R]): CanEqual[MyClass[L], MyClass[R]] = CanEqual.derived I would have expected a |
@nicolasstucki @odersky I would argue that my understanding of strict equality feature was merely about making equality checks safer at compiler time, not to actually change the semantics of case class equality. |
To be fair, I was hoping that CanEqual for case classes would simply delegate to case class generated equality. |
It does, CanEqual has no methods to call, the |
Sorry for the perseverance, but what's the outcome here? I disagree that the feature works as expected for this case and CanEqual derivation can be improved. I'm happy to be proven wrong if you point me to the documentation explaining why |
ok so in this case you would want a feature change so that |
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
Scala 3.1.1
Minimized code
Output
Expectation
Something is not part of case class universal equality check so it shouldn't be part of multiversal equality constraint either
The text was updated successfully, but these errors were encountered: