@@ -16,6 +16,7 @@ import reporting.*
16
16
import config .Printers .{ transforms => debug }
17
17
18
18
import patmat .Typ
19
+ import dotty .tools .dotc .util .SrcPos
19
20
20
21
/** This transform normalizes type tests and type casts,
21
22
* also replacing type tests with singleton argument type with reference equality check
@@ -358,11 +359,8 @@ object TypeTestsCasts {
358
359
if (sym.isTypeTest) {
359
360
val argType = tree.args.head.tpe
360
361
val isTrusted = tree.hasAttachment(PatternMatcher .TrustedTypeTestKey )
361
- val isUnchecked = expr.tpe.widenTermRefExpr.hasAnnotation(defn.UncheckedAnnot )
362
- if ! isTrusted && ! isUnchecked then
363
- val whyNot = whyUncheckable(expr.tpe, argType, tree.span)
364
- if whyNot.nonEmpty then
365
- report.uncheckedWarning(UncheckedTypePattern (argType, whyNot), expr.srcPos)
362
+ if ! isTrusted then
363
+ checkTypePattern(expr.tpe, argType, expr.srcPos)
366
364
transformTypeTest(expr, argType,
367
365
flagUnrelated = enclosingInlineds.isEmpty) // if test comes from inlined code, dont't flag it even if it always false
368
366
}
@@ -381,6 +379,19 @@ object TypeTestsCasts {
381
379
interceptWith(expr)
382
380
}
383
381
382
+ /** After PatternMatcher, only Bind nodes are present in simple try-catch trees
383
+ * See i19013
384
+ */
385
+ def checkBind (tree : Bind )(using Context ) =
386
+ checkTypePattern(defn.ThrowableType , tree.body.tpe, tree.srcPos)
387
+
388
+ private def checkTypePattern (exprTpe : Type , castTpe : Type , pos : SrcPos )(using Context ) =
389
+ val isUnchecked = exprTpe.widenTermRefExpr.hasAnnotation(defn.UncheckedAnnot )
390
+ if ! isUnchecked then
391
+ val whyNot = whyUncheckable(exprTpe, castTpe, pos.span)
392
+ if whyNot.nonEmpty then
393
+ report.uncheckedWarning(UncheckedTypePattern (castTpe, whyNot), pos)
394
+
384
395
private def effectiveClass (tp : Type )(using Context ): Symbol =
385
396
if tp.isRef(defn.PairClass ) then effectiveClass(erasure(tp))
386
397
else if tp.isRef(defn.AnyValClass ) then defn.AnyClass
0 commit comments