Skip to content

Commit eb90deb

Browse files
committed
Fix SeqFactoryClass#unapplySeq
Previously `defn.ListType.appliedTo(elemTp) <:< pat.tpe` failed when pat.tpe is something like ParamClause, an alias.
1 parent 79c6341 commit eb90deb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ object SpaceEngine {
352352
val funRef = fun1.tpe.asInstanceOf[TermRef]
353353
if (fun.symbol.name == nme.unapplySeq)
354354
val (arity, elemTp, resultTp) = unapplySeqInfo(fun.tpe.widen.finalResultType, fun.srcPos)
355-
if (fun.symbol.owner == defn.SeqFactoryClass && defn.ListType.appliedTo(elemTp) <:< pat.tpe)
355+
if fun.symbol.owner == defn.SeqFactoryClass && pat.tpe.hasClassSymbol(defn.ListClass) then
356356
// The exhaustivity and reachability logic already handles decomposing sum types (into its subclasses)
357357
// and product types (into its components). To get better counter-examples for patterns that are of type
358358
// List (or a super-type of list, like LinearSeq) we project them into spaces that use `::` and Nil.

tests/warn/i20132.list-Seq.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class D1
2+
class D2
3+
4+
class Test1:
5+
type Ds = List[D1] | List[D2]
6+
def m1(dss: List[Ds]) =
7+
dss.flatMap:
8+
case Seq(d) => Some(1)
9+
case Seq(head, tail*) => Some(2)
10+
case Seq() => None

0 commit comments

Comments
 (0)