Enumeration does not derive `CanEqual` for `strictEquality`

What is the reason enumeration does not derive CanEqual?
It was very surprising that this is not the default case, which led me to submit the following issue:

However, only after I noticed that the test cases explicitly check the interaction of enums and strictEquality, I understood that this is an intended design decision.

11 Likes

I started experimenting with strictEquality just recently. Once it’s on it pretty much requires you to have it specified on every case class that will participate in pattern matching.

1 Like

IME so far it’s strictly worse than Scala 2’s linting support + -Xfatal-warnings.

In Scala 2 you do literally nothing and get actionable errors for the cases you care about (i.e. where you are mistakenly comparing values of different types).

In Scala 3 you have to pepper derives CanEqual on every non-primitive type where you’ll be doing equality checking.

For example, here are some ScalaTest failures that have me considering giving up and disabling strictEquality in sbt test scope.

assert(x == Some(model))

Values of types Option[User] and Some[User] cannot be compared with == or !=

assert(x == List(model))

Values of types List[User] and List[User] cannot be compared with == or !=

Compared to Scala 2 it’s kind of like the tail wagging the dog, but I guess this is the only solution until linting support lands in Scala 3.

3 Likes