@@ -7,7 +7,7 @@ import Types._
77import Contexts ._
88import Flags ._
99import ast .Trees ._
10- import ast .{ tpd , untpd }
10+ import ast .tpd
1111import Decorators ._
1212import Symbols ._
1313import StdNames ._
@@ -404,21 +404,37 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
404404 else
405405 Prod (pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, pats.map(project), irrefutable(fun))
406406 case Typed (pat @ UnApply (_, _, _), _) => project(pat)
407- case Typed (expr, _) => Typ (erase(expr.tpe.stripAnnots), true )
407+ case Typed (expr, tpt) =>
408+ val unchecked = expr.tpe.hasAnnotation(ctx.definitions.UncheckedAnnot )
409+ def warn (msg : String ): Unit = if (! unchecked) ctx.warning(UncheckedTypePattern (msg), tpt.pos)
410+ Typ (erase(expr.tpe.stripAnnots)(warn), true )
408411 case _ =>
409412 debug.println(s " unknown pattern: $pat" )
410413 Empty
411414 }
412415
413416 /* Erase a type binding according to erasure semantics in pattern matching */
414- def erase (tp : Type ): Type = tp match {
417+ def erase (tp : Type )( implicit warn : String => Unit ) : Type = tp match {
415418 case tp @ AppliedType (tycon, args) =>
416419 if (tycon.isRef(defn.ArrayClass )) tp.derivedAppliedType(tycon, args.map(erase))
417- else tp.derivedAppliedType(tycon, args.map(t => WildcardType ))
420+ else {
421+ val ignoreWarning = args.forall { p =>
422+ p.typeSymbol.is(BindDefinedType ) ||
423+ p.hasAnnotation(defn.UncheckedAnnot ) ||
424+ p.isInstanceOf [TypeBounds ]
425+ }
426+ if (! ignoreWarning)
427+ warn(" type arguments are not checked since they are eliminated by erasure" )
428+
429+ tp.derivedAppliedType(tycon, args.map(t => WildcardType ))
430+ }
418431 case OrType (tp1, tp2) =>
419432 OrType (erase(tp1), erase(tp2))
420433 case AndType (tp1, tp2) =>
421434 AndType (erase(tp1), erase(tp2))
435+ case tp : RefinedType =>
436+ warn(" type refinement is not checked since it is eliminated by erasure" )
437+ tp.derivedRefinedType(erase(tp.parent), tp.refinedName, WildcardType )
422438 case _ => tp
423439 }
424440
@@ -740,12 +756,10 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
740756 }
741757
742758 def checkable (tree : Match ): Boolean = {
743- def isCheckable (tp : Type ): Boolean = tp match {
744- case AnnotatedType (tp, annot) =>
745- (ctx.definitions.UncheckedAnnot != annot.symbol) && isCheckable(tp)
746- case _ =>
747- // Possible to check everything, but be compatible with scalac by default
748- ctx.settings.YcheckAllPatmat .value ||
759+ // Possible to check everything, but be compatible with scalac by default
760+ def isCheckable (tp : Type ): Boolean =
761+ ! tp.hasAnnotation(defn.UncheckedAnnot ) && (
762+ ctx.settings.YcheckAllPatmat .value ||
749763 tp.typeSymbol.is(Sealed ) ||
750764 tp.isInstanceOf [OrType ] ||
751765 (tp.isInstanceOf [AndType ] && {
@@ -756,7 +770,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
756770 tp.typeSymbol.is(Enum ) ||
757771 canDecompose(tp) ||
758772 (defn.isTupleType(tp) && tp.dealias.argInfos.exists(isCheckable(_)))
759- }
773+ )
760774
761775 val Match (sel, cases) = tree
762776 val res = isCheckable(sel.tpe.widen.dealiasKeepAnnots)
0 commit comments