@@ -16,6 +16,7 @@ import reporting.*
1616import config .Printers .{ transforms => debug }
1717
1818import patmat .Typ
19+ import dotty .tools .dotc .util .SrcPos
1920
2021/** This transform normalizes type tests and type casts,
2122 * also replacing type tests with singleton argument type with reference equality check
@@ -358,11 +359,8 @@ object TypeTestsCasts {
358359 if (sym.isTypeTest) {
359360 val argType = tree.args.head.tpe
360361 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)
366364 transformTypeTest(expr, argType,
367365 flagUnrelated = enclosingInlineds.isEmpty) // if test comes from inlined code, dont't flag it even if it always false
368366 }
@@ -381,6 +379,19 @@ object TypeTestsCasts {
381379 interceptWith(expr)
382380 }
383381
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+
384395 private def effectiveClass (tp : Type )(using Context ): Symbol =
385396 if tp.isRef(defn.PairClass ) then effectiveClass(erasure(tp))
386397 else if tp.isRef(defn.AnyValClass ) then defn.AnyClass
0 commit comments