@@ -1335,9 +1335,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
13351335 def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
13361336 result.withNotNullInfo(
13371337 if result.thenp.tpe.isRef(defn.NothingClass ) then
1338- elsePathInfo.withOnceRetracted (thenPathInfo)
1338+ elsePathInfo.withRetracted (thenPathInfo)
13391339 else if result.elsep.tpe.isRef(defn.NothingClass ) then
1340- thenPathInfo.withOnceRetracted (elsePathInfo)
1340+ thenPathInfo.withRetracted (elsePathInfo)
13411341 else thenPathInfo.alt(elsePathInfo)
13421342 )
13431343 end typedIf
@@ -1871,9 +1871,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
18711871 def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
18721872 val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
18731873 .asInstanceOf [List [CaseDef ]]
1874- var nni = sel.notNullInfo
1875- if cases1.nonEmpty then nni = nni .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
1876- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nni )
1874+ var nnInfo = sel.notNullInfo
1875+ if cases1.nonEmpty then nnInfo = nnInfo .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
1876+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nnInfo )
18771877 }
18781878
18791879 def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType : Type , pt : Type )(using Context ): List [CaseDef ] =
@@ -2053,7 +2053,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
20532053 val capabilityProof = caughtExceptions.reduce(OrType (_, _, true ))
20542054 untpd.Block (makeCanThrow(capabilityProof), expr)
20552055
2056- def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try = {
2056+ def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try =
2057+ var nnInfo = NotNullInfo .empty
20572058 val expr2 :: cases2x = harmonic(harmonize, pt) {
20582059 // We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
20592060 // uses the types of patterns in `tree.cases` to determine the capabilities.
@@ -2065,25 +2066,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
20652066 val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
20662067 val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
20672068 val expr1 = typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
2068- val casesCtx = ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
2069+
2070+ // Since we don't know at which point the the exception is thrown in the body,
2071+ // we have to collect any reference that is once retracted.
2072+ nnInfo = expr1.notNullInfo.retractedInfo
2073+
2074+ val casesCtx = ctx.addNotNullInfo(nnInfo)
20692075 val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using casesCtx)
20702076 expr1 :: cases1
20712077 }: @ unchecked
20722078 val cases2 = cases2x.asInstanceOf [List [CaseDef ]]
20732079
2074- // Since we don't know at which point the the exception is thrown in the body,
2075- // we have to collect any reference that is once retracted.
2076- var nni = expr2.notNullInfo.onceRetractedInfo
20772080 // It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
20782081 // Therefore, the code in the finallizer and after the try block can only rely on the retracted
20792082 // info from the cases' body.
2080- if cases2.nonEmpty then nni = nni.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
2081-
2082- val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nni))
2083- nni = nni.seq(finalizer1.notNullInfo)
2083+ if cases2.nonEmpty then
2084+ nnInfo = nnInfo.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
20842085
2085- assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nni)
2086- }
2086+ val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nnInfo))
2087+ nnInfo = nnInfo.seq(finalizer1.notNullInfo)
2088+ assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nnInfo)
20872089
20882090 def typedTry (tree : untpd.ParsedTry , pt : Type )(using Context ): Try =
20892091 val cases : List [untpd.CaseDef ] = tree.handler match
0 commit comments