Open seigert opened 1 year ago
Thanks for the report!
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
.