@@ -2329,14 +2329,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23292329 untpd.Block (makeCanThrow(capabilityProof), expr)
23302330
23312331 def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try = {
2332- // We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2333- // uses the types of patterns in `tree.cases` to determine the capabilities.
2334- // Hence, we create a copy of cases with empty body and type check that first, then type check
2335- // the rest of the tree in order.
2336- val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
2337- val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
2338-
23392332 val expr2 :: cases2x = harmonic(harmonize, pt) {
2333+ // We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2334+ // uses the types of patterns in `tree.cases` to determine the capabilities.
2335+ // Hence, we create a copy of cases with empty body and type check that first, then type check
2336+ // the rest of the tree in order.
2337+ // It may seem that invalid references can be created if the type of the pattern contains
2338+ // type binds, but this is not a valid `CanThrow` capability (checked by `addCanThrowCapabilities`),
2339+ // so it is not a problem.
2340+ val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
2341+ val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
23402342 val expr1 = typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
23412343 val casesCtx = ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
23422344 val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using casesCtx)
0 commit comments