@@ -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
@@ -2153,9 +2153,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
21532153 def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
21542154 val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
21552155 .asInstanceOf [List [CaseDef ]]
2156- var nni = sel.notNullInfo
2157- if cases1.nonEmpty then nni = nni .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2158- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nni )
2156+ var nnInfo = sel.notNullInfo
2157+ if cases1.nonEmpty then nnInfo = nnInfo .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2158+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nnInfo )
21592159 }
21602160
21612161 def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType0 : Type , pt : Type )(using Context ): List [CaseDef ] =
@@ -2337,7 +2337,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23372337 val capabilityProof = caughtExceptions.reduce(OrType (_, _, true ))
23382338 untpd.Block (makeCanThrow(capabilityProof), expr)
23392339
2340- def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try = {
2340+ def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try =
2341+ var nnInfo = NotNullInfo .empty
23412342 val expr2 :: cases2x = harmonic(harmonize, pt) {
23422343 // We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
23432344 // uses the types of patterns in `tree.cases` to determine the capabilities.
@@ -2349,25 +2350,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23492350 val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
23502351 val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
23512352 val expr1 = typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
2352- val casesCtx = ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
2353+
2354+ // Since we don't know at which point the the exception is thrown in the body,
2355+ // we have to collect any reference that is once retracted.
2356+ nnInfo = expr1.notNullInfo.retractedInfo
2357+
2358+ val casesCtx = ctx.addNotNullInfo(nnInfo)
23532359 val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using casesCtx)
23542360 expr1 :: cases1
23552361 }: @ unchecked
23562362 val cases2 = cases2x.asInstanceOf [List [CaseDef ]]
23572363
2358- // Since we don't know at which point the the exception is thrown in the body,
2359- // we have to collect any reference that is once retracted.
2360- var nni = expr2.notNullInfo.onceRetractedInfo
23612364 // It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
23622365 // Therefore, the code in the finallizer and after the try block can only rely on the retracted
23632366 // info from the cases' body.
2364- if cases2.nonEmpty then nni = nni.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
2365-
2366- val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nni))
2367- nni = nni.seq(finalizer1.notNullInfo)
2367+ if cases2.nonEmpty then
2368+ nnInfo = nnInfo.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
23682369
2369- assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nni)
2370- }
2370+ val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nnInfo))
2371+ nnInfo = nnInfo.seq(finalizer1.notNullInfo)
2372+ assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nnInfo)
23712373
23722374 def typedTry (tree : untpd.ParsedTry , pt : Type )(using Context ): Try =
23732375 val cases : List [untpd.CaseDef ] = tree.handler match
0 commit comments