diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 1f0a673f90b1..412db22c98b5 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -534,6 +534,7 @@ class Definitions { @tu lazy val ConsClass: Symbol = requiredClass("scala.collection.immutable.::") def ConsType: TypeRef = ConsClass.typeRef @tu lazy val SeqFactoryClass: Symbol = requiredClass("scala.collection.SeqFactory") + @tu lazy val SeqFactoryClass_unapplySeq: Symbol = SeqFactoryClass.requiredMethod(nme.unapplySeq) @tu lazy val PreciseClass: ClassSymbol = requiredClass("scala.Precise") diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 5ca8cc247b52..2ee5917de831 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 == defn.SeqFactoryClass_unapplySeq 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