Given:
object A {
opaque type Foo = Int | String
}
object B {
def test(x: Any) = x match {
case x: A.Foo =>
println(x)
case _ =>
}
}
We get:
-- Warning: try/iso.scala:6:9 --------------------------------------------------
6 | case x: A.Foo =>
| ^^^^^^^^
| the type test for A.Foo cannot be checked at runtime
But Dotty is being too hard on itself here: it actually was able to generate a perfectly valid type test, I suspect that the logic in https://github.com/lampepfl/dotty/blob/10091bd6aef67580eb8e786444c225568f831255/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala#L33-L56 does not handle opaque types correctly.