@@ -365,23 +365,25 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
365
365
}
366
366
367
367
/* Erase pattern bound types with WildcardType */
368
- def erase (tp : Type ): Type = trace(i " $tp erased to " , debug) {
368
+ private def erase (tp : Type , inArray : Boolean = false ): Type = trace(i " $tp erased to " , debug) {
369
369
def isPatternTypeSymbol (sym : Symbol ) = ! sym.isClass && sym.is(Case )
370
370
371
- val map = new TypeMap {
372
- def apply (tp : Type ) = tp match {
373
- case tp @ AppliedType (tycon, args) if (tycon.isRef(defn.ArrayClass )) =>
374
- // cannot use WildcardType for Array[_], due to that
375
- // Array[WildcardType] <: Array[Array[WildcardType]]
376
- // see tests/patmat/t2425.scala
377
- tp
378
- case tref : TypeRef if isPatternTypeSymbol(tref.typeSymbol) =>
379
- WildcardType (tref.underlying.bounds)
380
- case _ => mapOver(tp)
381
- }
371
+ tp match {
372
+ case tp @ AppliedType (tycon, args) =>
373
+ if (tycon.isRef(defn.ArrayClass )) tp.derivedAppliedType(tycon, args.map(arg => erase(arg, inArray = true )))
374
+ else tp.derivedAppliedType(tycon, args.map(arg => erase(arg, inArray = false )))
375
+ case OrType (tp1, tp2) =>
376
+ OrType (erase(tp1, inArray), erase(tp2, inArray))
377
+ case AndType (tp1, tp2) =>
378
+ AndType (erase(tp1, inArray), erase(tp2, inArray))
379
+ case tp @ RefinedType (parent, _, _) =>
380
+ erase(parent)
381
+ case tref : TypeRef if isPatternTypeSymbol(tref.typeSymbol) =>
382
+ if (inArray) tref.underlying else WildcardType (tref.underlying.bounds)
383
+ case mt : MethodType =>
384
+ mt.derivedLambdaType(mt.paramNames, mt.paramInfos.map(info => erase(info)), erase(mt.resType))
385
+ case _ => tp
382
386
}
383
-
384
- map(tp)
385
387
}
386
388
387
389
/** Space of the pattern: unapplySeq(a, b, c: _*)
0 commit comments