@@ -2048,14 +2048,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
20482048      untpd.Block (makeCanThrow(capabilityProof), expr)
20492049
20502050  def  typedTry (tree : untpd.Try , pt : Type )(using  Context ):  Try  =  {
2051-     //  We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2052-     //  uses the types of patterns in `tree.cases` to determine the capabilities.
2053-     //  Hence, we create a copy of cases with empty body and type check that first, then type check
2054-     //  the rest of the tree in order.
2055-     val  casesEmptyBody1  =  tree.cases.mapconserve(cpy.CaseDef (_)(body =  EmptyTree ))
2056-     val  casesEmptyBody2  =  typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
2057- 
20582051    val  expr2  ::  cases2x =  harmonic(harmonize, pt) {
2052+       //  We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2053+       //  uses the types of patterns in `tree.cases` to determine the capabilities.
2054+       //  Hence, we create a copy of cases with empty body and type check that first, then type check
2055+       //  the rest of the tree in order.
2056+       //  It may seem that invalid references can be created if the type of the pattern contains
2057+       //  type binds, but this is not a valid `CanThrow` capability (checked by `addCanThrowCapabilities`),
2058+       //  so it is not a problem.
2059+       val  casesEmptyBody1  =  tree.cases.mapconserve(cpy.CaseDef (_)(body =  EmptyTree ))
2060+       val  casesEmptyBody2  =  typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
20592061      val  expr1  =  typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
20602062      val  casesCtx  =  ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
20612063      val  cases1  =  typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using  casesCtx)
0 commit comments