diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 5ca8cc247b52..9a373ad3653d 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -352,7 +352,7 @@ object SpaceEngine { val funRef = fun1.tpe.asInstanceOf[TermRef] if (fun.symbol.name == nme.unapplySeq) val (arity, elemTp, resultTp) = unapplySeqInfo(fun.tpe.widen.finalResultType, fun.srcPos) - if (fun.symbol.owner == defn.SeqFactoryClass && defn.ListType.appliedTo(elemTp) <:< pat.tpe) + if fun.symbol.owner == defn.SeqFactoryClass && pat.tpe.hasClassSymbol(defn.ListClass) then // The exhaustivity and reachability logic already handles decomposing sum types (into its subclasses) // and product types (into its components). To get better counter-examples for patterns that are of type // List (or a super-type of list, like LinearSeq) we project them into spaces that use `::` and Nil. diff --git a/tests/warn/i20132.list-Seq.scala b/tests/warn/i20132.list-Seq.scala new file mode 100644 index 000000000000..95d6e962d547 --- /dev/null +++ b/tests/warn/i20132.list-Seq.scala @@ -0,0 +1,10 @@ +class D1 +class D2 + +class Test1: + type Ds = List[D1] | List[D2] + def m1(dss: List[Ds]) = + dss.flatMap: + case Seq(d) => Some(1) + case Seq(head, tail*) => Some(2) + case Seq() => None