@@ -1544,9 +1544,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15441544    def  elsePathInfo  =  cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
15451545    result.withNotNullInfo(
15461546      if  result.thenp.tpe.isRef(defn.NothingClass ) then 
1547-         elsePathInfo.withOnceRetracted (thenPathInfo)
1547+         elsePathInfo.withRetracted (thenPathInfo)
15481548      else  if  result.elsep.tpe.isRef(defn.NothingClass ) then 
1549-         thenPathInfo.withOnceRetracted (elsePathInfo)
1549+         thenPathInfo.withRetracted (elsePathInfo)
15501550      else  thenPathInfo.alt(elsePathInfo)
15511551    )
15521552  end  typedIf 
@@ -2143,9 +2143,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
21432143  def  typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using  Context ):  Tree  =  {
21442144    val  cases1  =  harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
21452145      .asInstanceOf [List [CaseDef ]]
2146-     var  nni  =  sel.notNullInfo
2147-     if  cases1.nonEmpty then  nni  =  nni .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2148-     assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nni )
2146+     var  nnInfo  =  sel.notNullInfo
2147+     if  cases1.nonEmpty then  nnInfo  =  nnInfo .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2148+     assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nnInfo )
21492149  }
21502150
21512151  def  typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType0 : Type , pt : Type )(using  Context ):  List [CaseDef ] = 
@@ -2327,7 +2327,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23272327      val  capabilityProof  =  caughtExceptions.reduce(OrType (_, _, true ))
23282328      untpd.Block (makeCanThrow(capabilityProof), expr)
23292329
2330-   def  typedTry (tree : untpd.Try , pt : Type )(using  Context ):  Try  =  {
2330+   def  typedTry (tree : untpd.Try , pt : Type )(using  Context ):  Try  = 
2331+     var  nnInfo  =  NotNullInfo .empty
23312332    val  expr2  ::  cases2x =  harmonic(harmonize, pt) {
23322333      //  We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
23332334      //  uses the types of patterns in `tree.cases` to determine the capabilities.
@@ -2339,25 +2340,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23392340      val  casesEmptyBody1  =  tree.cases.mapconserve(cpy.CaseDef (_)(body =  EmptyTree ))
23402341      val  casesEmptyBody2  =  typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
23412342      val  expr1  =  typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
2342-       val  casesCtx  =  ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
2343+ 
2344+       //  Since we don't know at which point the the exception is thrown in the body,
2345+       //  we have to collect any reference that is once retracted.
2346+       nnInfo =  expr1.notNullInfo.retractedInfo
2347+ 
2348+       val  casesCtx  =  ctx.addNotNullInfo(nnInfo)
23432349      val  cases1  =  typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using  casesCtx)
23442350      expr1 ::  cases1
23452351    }:  @ unchecked
23462352    val  cases2  =  cases2x.asInstanceOf [List [CaseDef ]]
23472353
2348-     //  Since we don't know at which point the the exception is thrown in the body,
2349-     //  we have to collect any reference that is once retracted.
2350-     var  nni  =  expr2.notNullInfo.onceRetractedInfo
23512354    //  It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
23522355    //  Therefore, the code in the finallizer and after the try block can only rely on the retracted
23532356    //  info from the cases' body.
2354-     if  cases2.nonEmpty then  nni =  nni.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
2355- 
2356-     val  finalizer1  =  typed(tree.finalizer, defn.UnitType )(using  ctx.addNotNullInfo(nni))
2357-     nni =  nni.seq(finalizer1.notNullInfo)
2357+     if  cases2.nonEmpty then 
2358+       nnInfo =  nnInfo.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
23582359
2359-     assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nni)
2360-   }
2360+     val  finalizer1  =  typed(tree.finalizer, defn.UnitType )(using  ctx.addNotNullInfo(nnInfo))
2361+     nnInfo =  nnInfo.seq(finalizer1.notNullInfo)
2362+     assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nnInfo)
23612363
23622364  def  typedTry (tree : untpd.ParsedTry , pt : Type )(using  Context ):  Try  = 
23632365    val  cases :  List [untpd.CaseDef ] =  tree.handler match 
0 commit comments