@@ -137,13 +137,15 @@ trait SpaceLogic {
137
137
/** Flatten space to get rid of `Or` for pretty print */
138
138
def flatten (space : Space ): List [Space ] = space match {
139
139
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
+ }
145
147
}
146
- case Or (spaces) =>
148
+ case Or (spaces) =>
147
149
spaces.flatMap(flatten _)
148
150
case _ => List (space)
149
151
}
@@ -166,7 +168,7 @@ trait SpaceLogic {
166
168
simplify(minus(a, b)) == Empty
167
169
case (Prod (tp1, _, _, _, _), Typ (tp2, _)) =>
168
170
isSubType(tp1, tp2)
169
- case (Typ (tp2 , _), Prod (tp1 , fun, sym, ss, full)) =>
171
+ case (Typ (tp1 , _), Prod (tp2 , fun, sym, ss, full)) =>
170
172
// approximation: a type can never be fully matched by a partial extractor
171
173
full && isSubType(tp1, tp2) && isSubspace(Prod (tp2, fun, sym, signature(fun, sym, ss.length).map(Typ (_, false )), full), b)
172
174
case (Prod (_, fun1, sym1, ss1, _), Prod (_, fun2, sym2, ss2, _)) =>
@@ -393,10 +395,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
393
395
if (fun.symbol.name == nme.unapplySeq)
394
396
projectSeq(pats)
395
397
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))
397
399
case Typed (pat @ UnApply (_, _, _), _) => project(pat)
398
400
case Typed (expr, _) => Typ (expr.tpe.stripAnnots, true )
399
401
case _ =>
402
+ debug.println(s " unknown pattern: $pat" )
400
403
Empty
401
404
}
402
405
0 commit comments