@@ -56,7 +56,7 @@ object TypeTestsCasts {
56
56
* 9. if `X` is `T1 | T2`, checkable(T1, P) && checkable(T2, P).
57
57
* 10. otherwise, ""
58
58
*/
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) {
60
60
extension (inline s1 : String ) inline def && (inline s2 : String ): String = if s1 == " " then s2 else s1
61
61
extension (inline b : Boolean ) inline def ||| (inline s : String ): String = if b then " " else s
62
62
@@ -143,7 +143,7 @@ object TypeTestsCasts {
143
143
case defn.ArrayOf (tpE) => recur(tpE, tpT)
144
144
case _ => recur(defn.AnyType , tpT)
145
145
}
146
- case tpe @ AppliedType (tycon, targs) =>
146
+ case tpe @ AppliedType (tycon, targs) if ! trustTypeApplication =>
147
147
X .widenDealias match {
148
148
case OrType (tp1, tp2) =>
149
149
// This case is required to retrofit type inference,
@@ -366,8 +366,7 @@ object TypeTestsCasts {
366
366
if (sym.isTypeTest) {
367
367
val argType = tree.args.head.tpe
368
368
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)
371
370
transformTypeTest(expr, argType,
372
371
flagUnrelated = enclosingInlineds.isEmpty) // if test comes from inlined code, dont't flag it even if it always false
373
372
}
@@ -392,10 +391,10 @@ object TypeTestsCasts {
392
391
def checkBind (tree : Bind )(using Context ) =
393
392
checkTypePattern(defn.ThrowableType , tree.body.tpe, tree.srcPos)
394
393
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 ) =
396
395
val isUnchecked = exprTpe.widenTermRefExpr.hasAnnotation(defn.UncheckedAnnot )
397
396
if ! isUnchecked then
398
- val whyNot = whyUncheckable(exprTpe, castTpe, pos.span)
397
+ val whyNot = whyUncheckable(exprTpe, castTpe, pos.span, trustTypeApplication )
399
398
if whyNot.nonEmpty then
400
399
report.uncheckedWarning(UncheckedTypePattern (castTpe, whyNot), pos)
401
400
0 commit comments