@@ -322,7 +322,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
322
322
case Ident (nme.WILDCARD ) =>
323
323
Or (Typ (pat.tpe.stripAnnots, false ) :: nullSpace :: Nil )
324
324
case Ident (_) | Select (_, _) =>
325
- Typ (pat.tpe.stripAnnots, false )
325
+ Typ (erase( pat.tpe.stripAnnots) , false )
326
326
case Alternative (trees) => Or (trees.map(project(_)))
327
327
case Bind (_, pat) => project(pat)
328
328
case SeqLiteral (pats, _) => projectSeq(pats)
@@ -338,16 +338,17 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
338
338
Prod (erase(pat.tpe.stripAnnots), fun.tpe, fun.symbol, pats.take(arity - 1 ).map(project) :+ projectSeq(pats.drop(arity - 1 )),isIrrefutableUnapply(fun))
339
339
}
340
340
else
341
- Prod (erase(pat.tpe.stripAnnots), fun.tpe, fun.symbol, pats.map(project), isIrrefutableUnapply(fun))
342
- case Typed (pat @ UnApply (_, _, _), _) => project(pat)
341
+ Prod (erase(pat.tpe.stripAnnots), erase(fun.tpe), fun.symbol, pats.map(project), isIrrefutableUnapply(fun))
342
+ case Typed (pat : UnApply , _) =>
343
+ project(pat)
343
344
case Typed (expr, tpt) =>
344
345
Typ (erase(expr.tpe.stripAnnots), true )
345
346
case This (_) =>
346
347
Typ (pat.tpe.stripAnnots, false )
347
348
case EmptyTree => // default rethrow clause of try/catch, check tests/patmat/try2.scala
348
349
Typ (WildcardType , false )
349
350
case _ =>
350
- debug.println (s " unknown pattern: $pat" )
351
+ ctx.error (s " unknown pattern: $pat" , pat.sourcePos )
351
352
Empty
352
353
}
353
354
@@ -364,13 +365,18 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
364
365
}
365
366
366
367
/* Erase pattern bound types with WildcardType */
367
- def erase (tp : Type ): Type = {
368
+ def erase (tp : Type ): Type = trace( i " $tp erased to " , debug) {
368
369
def isPatternTypeSymbol (sym : Symbol ) = ! sym.isClass && sym.is(Case )
369
370
370
371
val map = new TypeMap {
371
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
+ TypeErasure .erasure(tp)
372
378
case tref : TypeRef if isPatternTypeSymbol(tref.typeSymbol) =>
373
- tref.underlying.bounds
379
+ WildcardType ( tref.underlying.bounds)
374
380
case _ => mapOver(tp)
375
381
}
376
382
}
0 commit comments