@@ -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
@@ -2143,9 +2143,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2143
2143
def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
2144
2144
val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
2145
2145
.asInstanceOf [List [CaseDef ]]
2146
- var nni = sel.notNullInfo
2147
- if cases1.nonEmpty then nni = nni .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2148
- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nni )
2146
+ var nnInfo = sel.notNullInfo
2147
+ if cases1.nonEmpty then nnInfo = nnInfo .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2148
+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nnInfo )
2149
2149
}
2150
2150
2151
2151
def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType0 : Type , pt : Type )(using Context ): List [CaseDef ] =
@@ -2327,7 +2327,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2327
2327
val capabilityProof = caughtExceptions.reduce(OrType (_, _, true ))
2328
2328
untpd.Block (makeCanThrow(capabilityProof), expr)
2329
2329
2330
- def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try = {
2330
+ def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try =
2331
+ var nnInfo = NotNullInfo .empty
2331
2332
val expr2 :: cases2x = harmonic(harmonize, pt) {
2332
2333
// We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2333
2334
// uses the types of patterns in `tree.cases` to determine the capabilities.
@@ -2339,25 +2340,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2339
2340
val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
2340
2341
val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
2341
2342
val expr1 = typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
2342
- val casesCtx = ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
2343
+
2344
+ // Since we don't know at which point the the exception is thrown in the body,
2345
+ // we have to collect any reference that is once retracted.
2346
+ nnInfo = expr1.notNullInfo.retractedInfo
2347
+
2348
+ val casesCtx = ctx.addNotNullInfo(nnInfo)
2343
2349
val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using casesCtx)
2344
2350
expr1 :: cases1
2345
2351
}: @ unchecked
2346
2352
val cases2 = cases2x.asInstanceOf [List [CaseDef ]]
2347
2353
2348
- // Since we don't know at which point the the exception is thrown in the body,
2349
- // we have to collect any reference that is once retracted.
2350
- var nni = expr2.notNullInfo.onceRetractedInfo
2351
2354
// It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
2352
2355
// Therefore, the code in the finallizer and after the try block can only rely on the retracted
2353
2356
// info from the cases' body.
2354
- if cases2.nonEmpty then nni = nni.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
2355
-
2356
- val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nni))
2357
- nni = nni.seq(finalizer1.notNullInfo)
2357
+ if cases2.nonEmpty then
2358
+ nnInfo = nnInfo.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
2358
2359
2359
- assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nni)
2360
- }
2360
+ val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nnInfo))
2361
+ nnInfo = nnInfo.seq(finalizer1.notNullInfo)
2362
+ assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nnInfo)
2361
2363
2362
2364
def typedTry (tree : untpd.ParsedTry , pt : Type )(using Context ): Try =
2363
2365
val cases : List [untpd.CaseDef ] = tree.handler match
0 commit comments