@@ -1544,9 +1544,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1544
1544
def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
1545
1545
result.withNotNullInfo(
1546
1546
if result.thenp.tpe.isRef(defn.NothingClass ) then
1547
- elsePathInfo.withOnceRetracted (thenPathInfo)
1547
+ elsePathInfo.withRetracted (thenPathInfo)
1548
1548
else if result.elsep.tpe.isRef(defn.NothingClass ) then
1549
- thenPathInfo.withOnceRetracted (elsePathInfo)
1549
+ thenPathInfo.withRetracted (elsePathInfo)
1550
1550
else thenPathInfo.alt(elsePathInfo)
1551
1551
)
1552
1552
end typedIf
@@ -2153,9 +2153,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2153
2153
def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
2154
2154
val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
2155
2155
.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 )
2159
2159
}
2160
2160
2161
2161
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
2337
2337
val capabilityProof = caughtExceptions.reduce(OrType (_, _, true ))
2338
2338
untpd.Block (makeCanThrow(capabilityProof), expr)
2339
2339
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
2341
2342
val expr2 :: cases2x = harmonic(harmonize, pt) {
2342
2343
// We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2343
2344
// uses the types of patterns in `tree.cases` to determine the capabilities.
@@ -2349,25 +2350,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2349
2350
val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
2350
2351
val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
2351
2352
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)
2353
2359
val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using casesCtx)
2354
2360
expr1 :: cases1
2355
2361
}: @ unchecked
2356
2362
val cases2 = cases2x.asInstanceOf [List [CaseDef ]]
2357
2363
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
2361
2364
// It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
2362
2365
// Therefore, the code in the finallizer and after the try block can only rely on the retracted
2363
2366
// 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(_)))
2368
2369
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)
2371
2373
2372
2374
def typedTry (tree : untpd.ParsedTry , pt : Type )(using Context ): Try =
2373
2375
val cases : List [untpd.CaseDef ] = tree.handler match
0 commit comments