diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 3763af243881..0a6b774b83dd 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -151,6 +151,7 @@ object TypeTestsCasts { // always false test warnings are emitted elsewhere X.classSymbol.exists && P.classSymbol.exists && !X.classSymbol.asClass.mayHaveCommonChild(P.classSymbol.asClass) + || X.classSymbol.isOneOf(FinalOrSealed) || typeArgsTrivial(X, tpe) ||| i"its type arguments can't be determined from $X" } diff --git a/tests/pos/16899.scala b/tests/pos/16899.scala new file mode 100644 index 000000000000..61d1b7dd404b --- /dev/null +++ b/tests/pos/16899.scala @@ -0,0 +1,5 @@ +sealed trait Unset + +def foo(v: Unset|Option[Int]): Unit = v match + case v: Unset => () + case v: Option[Int] => () \ No newline at end of file