Skip to content

Commit

Permalink
Fix SeqFactoryClass_unapplySeq
Browse files Browse the repository at this point in the history
Previously `defn.ListType.appliedTo(elemTp) <:< pat.tpe` failed when
pat.tpe is something like ParamClause, an alias.
  • Loading branch information
dwijnand committed Jul 5, 2024
1 parent 79c6341 commit 2915c25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions tests/warn/i20132.list-Seq.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2915c25

Please sign in to comment.