Skip to content

Commit 184ec22

Browse files
committed
fix flatten and isSubspace
1 parent 21d983c commit 184ec22

File tree

1 file changed

+11
-8
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,15 @@ trait SpaceLogic {
137137
/** Flatten space to get rid of `Or` for pretty print */
138138
def flatten(space: Space): List[Space] = space match {
139139
case Prod(tp, fun, sym, spaces, full) =>
140-
val flats = spaces.map(flatten _)
141-
142-
flats.foldLeft(List[Prod]()) { (acc, flat) =>
143-
if (acc.isEmpty) flat.map(s => Prod(tp, fun, sym, s :: Nil, full))
144-
else for (Prod(tp, fun, sym, ss, full) <- acc; s <- flat) yield Prod(tp, fun, sym, ss :+ s, full)
140+
spaces.map(flatten) match {
141+
case Nil => Prod(tp, fun, sym, Nil, full) :: Nil
142+
case ss =>
143+
ss.foldLeft(List[Prod]()) { (acc, flat) =>
144+
if (acc.isEmpty) flat.map(s => Prod(tp, fun, sym, s :: Nil, full))
145+
else for (Prod(tp, fun, sym, ss, full) <- acc; s <- flat) yield Prod(tp, fun, sym, ss :+ s, full)
146+
}
145147
}
146-
case Or(spaces) =>
148+
case Or(spaces) =>
147149
spaces.flatMap(flatten _)
148150
case _ => List(space)
149151
}
@@ -166,7 +168,7 @@ trait SpaceLogic {
166168
simplify(minus(a, b)) == Empty
167169
case (Prod(tp1, _, _, _, _), Typ(tp2, _)) =>
168170
isSubType(tp1, tp2)
169-
case (Typ(tp2, _), Prod(tp1, fun, sym, ss, full)) =>
171+
case (Typ(tp1, _), Prod(tp2, fun, sym, ss, full)) =>
170172
// approximation: a type can never be fully matched by a partial extractor
171173
full && isSubType(tp1, tp2) && isSubspace(Prod(tp2, fun, sym, signature(fun, sym, ss.length).map(Typ(_, false)), full), b)
172174
case (Prod(_, fun1, sym1, ss1, _), Prod(_, fun2, sym2, ss2, _)) =>
@@ -393,10 +395,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
393395
if (fun.symbol.name == nme.unapplySeq)
394396
projectSeq(pats)
395397
else
396-
Prod(pat.tpe.stripAnnots, fun.tpe, fun.symbol, pats.map(pat => project(pat)), irrefutable(fun))
398+
Prod(pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, pats.map(pat => project(pat)), irrefutable(fun))
397399
case Typed(pat @ UnApply(_, _, _), _) => project(pat)
398400
case Typed(expr, _) => Typ(expr.tpe.stripAnnots, true)
399401
case _ =>
402+
debug.println(s"unknown pattern: $pat")
400403
Empty
401404
}
402405

0 commit comments

Comments
 (0)