Strict equality CanEqual derivation fails for classes in which type argument is not used for equality
See original GitHub issueCompiler version
Scala 3.1.1
Minimized code
import scala.language.strictEquality
case class MyClass[A](value: String)(val a: A) derives CanEqual
class Something {}
val a = MyClass[Something]("some")(new Something())
val b = MyClass[Something]("some")(new Something())
println(a == b)
Output
Values of types Playground.MyClass[Playground.Something] and Playground.MyClass[Playground.Something] cannot be compared with == or !=.
I found:
Playground.MyClass.derived$CanEqual[Playground.Something, Playground.Something](
/* missing */summon[CanEqual[Playground.Something, Playground.Something]]
)
But no implicit values were found that match type CanEqual[Playground.Something, Playground.Something].
Expectation
Something is not part of case class universal equality check so it shouldn’t be part of multiversal equality constraint either
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Strict equality (===) - JavaScript - MDN Web Docs
The strict equality (===) operator checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality ......
Read more >Multiversal Equality - Scala 3 - EPFL
Multiversal equality is an opt-in way to make universal equality safer. It uses a binary type class scala.CanEqual to indicate that values of...
Read more >Multiversal Equality | Scala 3 — Book
It uses the binary type class CanEqual to indicate that values of two given types can be compared with each other. Allowing the...
Read more >Multiversal Equality in Scala 3 | Baeldung on Scala
There are two different ways we can create CanEqual instances. 4.1. Using Type-Class Derivation.
Read more >Groovy Language Documentation
Support classes; Class nodes; Helping the type checker; Throwing an error ... In Groovy, using == to test equality is different from using...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@spameggo you need to enable strict quality via:
import scala.language.strictEquality
ok so in this case you would want a feature change so that
CanEqual
derivation can analyse the equals method - this is hard in general, but making it specialised for this one use case of “if user does not define custom equals, and generic type parameter does not appear in primary constructor of case class” could be possible