@@ -1553,9 +1553,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1553
1553
def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
1554
1554
result.withNotNullInfo(
1555
1555
if result.thenp.tpe.isRef(defn.NothingClass ) then
1556
- elsePathInfo.withOnceRetracted (thenPathInfo)
1556
+ elsePathInfo.withRetracted (thenPathInfo)
1557
1557
else if result.elsep.tpe.isRef(defn.NothingClass ) then
1558
- thenPathInfo.withOnceRetracted (elsePathInfo)
1558
+ thenPathInfo.withRetracted (elsePathInfo)
1559
1559
else thenPathInfo.alt(elsePathInfo)
1560
1560
)
1561
1561
end typedIf
@@ -2150,9 +2150,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2150
2150
def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
2151
2151
val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
2152
2152
.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 )
2156
2156
}
2157
2157
2158
2158
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
2334
2334
val capabilityProof = caughtExceptions.reduce(OrType (_, _, true ))
2335
2335
untpd.Block (makeCanThrow(capabilityProof), expr)
2336
2336
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
2338
2339
val expr2 :: cases2x = harmonic(harmonize, pt) {
2339
2340
// We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2340
2341
// uses the types of patterns in `tree.cases` to determine the capabilities.
@@ -2346,25 +2347,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2346
2347
val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
2347
2348
val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
2348
2349
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)
2350
2356
val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using casesCtx)
2351
2357
expr1 :: cases1
2352
2358
}: @ unchecked
2353
2359
val cases2 = cases2x.asInstanceOf [List [CaseDef ]]
2354
2360
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
2358
2361
// It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
2359
2362
// Therefore, the code in the finallizer and after the try block can only rely on the retracted
2360
2363
// 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(_)))
2365
2366
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)
2368
2370
2369
2371
def typedTry (tree : untpd.ParsedTry , pt : Type )(using Context ): Try =
2370
2372
val cases : List [untpd.CaseDef ] = tree.handler match
0 commit comments