That’s fair!
However, strictEquality doesn’t apply to eq, so again, it would defeat the whole purpose here.
That is objectively true, but
- it is relatively uncommon to override
equals, and - I would argue something like
override def equals(other: Object): Boolean = falseis a bug / incorrect, even though it’s valid code; it should at the very least bethis eq other(and I can’t think of a case where that would be undesired)
Is strictEquality the vehicle “to reinstate some checks that weren’t ported”, or will it be something else?
Taking a couple steps back, I became interested in this topic after shipping some code that was comparing two unrelated types. When I found the issue, I was shocked (coming from Scala 2, I expected to receive the compiler warning about comparing unrelated types that you showed above!). I can’t remember what exactly led me to strictEquality (I think maybe it was trying to get scapegoat or scalafix to surface the error, or some other page somewhere that said the language flag has to be enabled?), but I was disappointed with how unruly CanEqual was and how much work I had to put in (on an existing codebase), simply for the compiler to give me a warning on 1 == “a”.
Maybe the aim of strictEquality is not really what I’m after; what I’m after is more or less as you said “to reinstate some checks that weren’t ported”. I’d love for some compiler setting/flag that basically does something as simple as (is it simple?):
Given an expression
a == b, if the closest common supertype (least upper bound?) ofaandbisAnyRefor anything higher (Any), then generate a warning.
Is that the same way it was implemented in Scala 2? Is this the relevant/related code?