@@ -56,7 +56,7 @@ object TypeTestsCasts {
5656 * 9. if `X` is `T1 | T2`, checkable(T1, P) && checkable(T2, P).
5757 * 10. otherwise, ""
5858 */
59- def whyUncheckable (X : Type , P : Type , span : Span )(using Context ): String = atPhase(Phases .refchecksPhase.next) {
59+ def whyUncheckable (X : Type , P : Type , span : Span , trustTypeApplication : Boolean )(using Context ): String = atPhase(Phases .refchecksPhase.next) {
6060 extension (inline s1 : String ) inline def && (inline s2 : String ): String = if s1 == " " then s2 else s1
6161 extension (inline b : Boolean ) inline def ||| (inline s : String ): String = if b then " " else s
6262
@@ -143,7 +143,7 @@ object TypeTestsCasts {
143143 case defn.ArrayOf (tpE) => recur(tpE, tpT)
144144 case _ => recur(defn.AnyType , tpT)
145145 }
146- case tpe @ AppliedType (tycon, targs) =>
146+ case tpe @ AppliedType (tycon, targs) if ! trustTypeApplication =>
147147 X .widenDealias match {
148148 case OrType (tp1, tp2) =>
149149 // This case is required to retrofit type inference,
@@ -366,8 +366,7 @@ object TypeTestsCasts {
366366 if (sym.isTypeTest) {
367367 val argType = tree.args.head.tpe
368368 val isTrusted = tree.hasAttachment(PatternMatcher .TrustedTypeTestKey )
369- if ! isTrusted then
370- checkTypePattern(expr.tpe, argType, expr.srcPos)
369+ checkTypePattern(expr.tpe, argType, expr.srcPos, isTrusted)
371370 transformTypeTest(expr, argType,
372371 flagUnrelated = enclosingInlineds.isEmpty) // if test comes from inlined code, dont't flag it even if it always false
373372 }
@@ -392,10 +391,10 @@ object TypeTestsCasts {
392391 def checkBind (tree : Bind )(using Context ) =
393392 checkTypePattern(defn.ThrowableType , tree.body.tpe, tree.srcPos)
394393
395- private def checkTypePattern (exprTpe : Type , castTpe : Type , pos : SrcPos )(using Context ) =
394+ private def checkTypePattern (exprTpe : Type , castTpe : Type , pos : SrcPos , trustTypeApplication : Boolean = false )(using Context ) =
396395 val isUnchecked = exprTpe.widenTermRefExpr.hasAnnotation(defn.UncheckedAnnot )
397396 if ! isUnchecked then
398- val whyNot = whyUncheckable(exprTpe, castTpe, pos.span)
397+ val whyNot = whyUncheckable(exprTpe, castTpe, pos.span, trustTypeApplication )
399398 if whyNot.nonEmpty then
400399 report.uncheckedWarning(UncheckedTypePattern (castTpe, whyNot), pos)
401400
0 commit comments