@@ -1553,9 +1553,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15531553 def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
15541554 result.withNotNullInfo(
15551555 if result.thenp.tpe.isRef(defn.NothingClass ) then
1556- elsePathInfo.withOnceRetracted (thenPathInfo)
1556+ elsePathInfo.withRetracted (thenPathInfo)
15571557 else if result.elsep.tpe.isRef(defn.NothingClass ) then
1558- thenPathInfo.withOnceRetracted (elsePathInfo)
1558+ thenPathInfo.withRetracted (elsePathInfo)
15591559 else thenPathInfo.alt(elsePathInfo)
15601560 )
15611561 end typedIf
@@ -2150,9 +2150,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
21502150 def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
21512151 val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
21522152 .asInstanceOf [List [CaseDef ]]
2153- var nni = sel.notNullInfo
2154- if cases1.nonEmpty then nni = nni .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2155- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nni )
2153+ var nnInfo = sel.notNullInfo
2154+ if cases1.nonEmpty then nnInfo = nnInfo .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2155+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nnInfo )
21562156 }
21572157
21582158 def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType0 : Type , pt : Type )(using Context ): List [CaseDef ] =
@@ -2334,7 +2334,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23342334 val capabilityProof = caughtExceptions.reduce(OrType (_, _, true ))
23352335 untpd.Block (makeCanThrow(capabilityProof), expr)
23362336
2337- def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try = {
2337+ def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try =
2338+ var nnInfo = NotNullInfo .empty
23382339 val expr2 :: cases2x = harmonic(harmonize, pt) {
23392340 // We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
23402341 // uses the types of patterns in `tree.cases` to determine the capabilities.
@@ -2346,25 +2347,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23462347 val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
23472348 val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
23482349 val expr1 = typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
2349- val casesCtx = ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
2350+
2351+ // Since we don't know at which point the the exception is thrown in the body,
2352+ // we have to collect any reference that is once retracted.
2353+ nnInfo = expr1.notNullInfo.retractedInfo
2354+
2355+ val casesCtx = ctx.addNotNullInfo(nnInfo)
23502356 val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using casesCtx)
23512357 expr1 :: cases1
23522358 }: @ unchecked
23532359 val cases2 = cases2x.asInstanceOf [List [CaseDef ]]
23542360
2355- // Since we don't know at which point the the exception is thrown in the body,
2356- // we have to collect any reference that is once retracted.
2357- var nni = expr2.notNullInfo.onceRetractedInfo
23582361 // It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
23592362 // Therefore, the code in the finallizer and after the try block can only rely on the retracted
23602363 // info from the cases' body.
2361- if cases2.nonEmpty then nni = nni.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
2362-
2363- val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nni))
2364- nni = nni.seq(finalizer1.notNullInfo)
2364+ if cases2.nonEmpty then
2365+ nnInfo = nnInfo.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
23652366
2366- assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nni)
2367- }
2367+ val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nnInfo))
2368+ nnInfo = nnInfo.seq(finalizer1.notNullInfo)
2369+ assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nnInfo)
23682370
23692371 def typedTry (tree : untpd.ParsedTry , pt : Type )(using Context ): Try =
23702372 val cases : List [untpd.CaseDef ] = tree.handler match
0 commit comments