This is a follow-up question of:
In Scala 3: Why runtime pattern matching can't work reliably on duck type using JVM reflection?
I'm trying to create a pattern matching implementation in Scala that is more resilient to type erasure. It should still rely on only JVM reflection on class but can degrade smoothly to alternatives in case of a runtime sanity check or class cast error.
The signature of my implementation looks like this:
@unchecked
case class Match[T](self: T) {
def apply[R](
@unchecked cases: PartialFunction[T, R]*
): R = ???
}
When testing it on a case that involves type erasure:
trait H {
type Unknown <: String
Match("abc": Serializable).apply(
{ case v: Unknown => 1 },
{ case v: Any => 2 }
)
}
I still got the warnings:
[Warn] /xxx.scala:20:19: abstract type pattern Has.this.Unknown is unchecked since it is eliminated by erasure
[Warn] /xxx.scala:20:16: The outer reference in this type test cannot be checked at run time.
It appears that @unchecked annotation has no effect on suppressing compiler message. This effectively rules out possibility to use partial function in my definition.
How can this warning be suppressed?