@@ -20,7 +20,6 @@ import ProtoTypes._
20
20
import transform .SymUtils ._
21
21
import reporting .diagnostic .messages ._
22
22
import config .Printers .{exhaustivity => debug }
23
- import util .Positions .Position
24
23
25
24
/** Space logic for checking exhaustivity and unreachability of pattern matching
26
25
*
@@ -404,20 +403,23 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
404
403
else
405
404
Prod (pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, pats.map(project), irrefutable(fun))
406
405
case Typed (pat @ UnApply (_, _, _), _) => project(pat)
407
- case Typed (expr, tp) => Typ (erase(expr.tpe.stripAnnots)(tp.pos), true )
406
+ case Typed (expr, tpt) =>
407
+ val unchecked = expr.tpe.hasAnnotation(ctx.definitions.UncheckedAnnot )
408
+ def warn (msg : String ): Unit = if (! unchecked) ctx.warning(UncheckedTypePattern (msg), tpt.pos)
409
+ Typ (erase(expr.tpe.stripAnnots)(warn), true )
408
410
case _ =>
409
411
debug.println(s " unknown pattern: $pat" )
410
412
Empty
411
413
}
412
414
413
415
/* Erase a type binding according to erasure semantics in pattern matching */
414
- def erase (tp : Type )(implicit pos : Position ): Type = tp match {
416
+ def erase (tp : Type )(implicit warn : String => Unit ): Type = tp match {
415
417
case tp @ AppliedType (tycon, args) =>
416
418
if (tycon.isRef(defn.ArrayClass )) tp.derivedAppliedType(tycon, args.map(erase))
417
419
else {
418
420
val ignoreWarning = args.forall(p => p.typeSymbol.is(BindDefinedType ) || p.isInstanceOf [TypeBounds ])
419
421
if (! ignoreWarning)
420
- ctx.warning( UncheckedTypePattern ( " type arguments are not checked since they are eliminated by erasure" ), pos )
422
+ warn( " type arguments are not checked since they are eliminated by erasure" )
421
423
422
424
tp.derivedAppliedType(tycon, args.map(t => WildcardType ))
423
425
}
@@ -426,7 +428,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
426
428
case AndType (tp1, tp2) =>
427
429
AndType (erase(tp1), erase(tp2))
428
430
case tp : RefinedType =>
429
- ctx.warning( UncheckedTypePattern ( " type refinement is not checked since it is eliminated by erasure" ), pos )
431
+ warn( " type refinement is not checked since it is eliminated by erasure" )
430
432
tp.derivedRefinedType(erase(tp.parent), tp.refinedName, WildcardType )
431
433
case _ => tp
432
434
}
0 commit comments