You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Scala 3 declaration of equals is def equals(obj: Any): Boolean = ???. This means that any attempt to match on a class instance in equals body is met with
[error] | pattern selector should be an instance of Matchable,,[error] | but it has unmatchable type Any instead
Official documentation suggest to fix this with obj.asInstanceOf[Matchable] as this is guaranteed to succeed.
But this triggers DisableSyntax.noAsInstanceOf rule for almost every custom .equals.
The text was updated successfully, but these errors were encountered:
I am hesitant to add an exception that would effectively change the semantics of DisableSyntax.noAsInstanceOf, especially since forcing usage of asInstanceOf serves a purpose per the documentation:
The cast of that to Matchable serves as an indication that universal equality is unsafe in the presence of abstract types and opaque types since it cannot properly distinguish the meaning of a type from its representation
Instead, I am thinking of having a custom lint diagnostic when finding a .asInstanceOf[Matchable], perhaps referencing the documentation and/or suggesting to use asMatchable?
I'd be happy to review a PR! The change should be fairly easy here. The rule is syntactic so we can't be sure it's the right scala.Matchable type, but it's acceptable to have false positives I believe. A Scala 3 testkit input asserting the diagnostic (example) should be added to guard that new behavior.
In Scala 3 declaration of
equals
isdef equals(obj: Any): Boolean = ???
. This means that any attempt to match on a class instance inequals
body is met withOfficial documentation suggest to fix this with
obj.asInstanceOf[Matchable]
as this is guaranteed to succeed.But this triggers
DisableSyntax.noAsInstanceOf
rule for almost every custom.equals
.The text was updated successfully, but these errors were encountered: