@@ -1335,9 +1335,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1335
1335
def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
1336
1336
result.withNotNullInfo(
1337
1337
if result.thenp.tpe.isRef(defn.NothingClass ) then
1338
- elsePathInfo.withOnceRetracted (thenPathInfo)
1338
+ elsePathInfo.withRetracted (thenPathInfo)
1339
1339
else if result.elsep.tpe.isRef(defn.NothingClass ) then
1340
- thenPathInfo.withOnceRetracted (elsePathInfo)
1340
+ thenPathInfo.withRetracted (elsePathInfo)
1341
1341
else thenPathInfo.alt(elsePathInfo)
1342
1342
)
1343
1343
end typedIf
@@ -1871,9 +1871,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1871
1871
def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
1872
1872
val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
1873
1873
.asInstanceOf [List [CaseDef ]]
1874
- var nni = sel.notNullInfo
1875
- if cases1.nonEmpty then nni = nni .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
1876
- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nni )
1874
+ var nnInfo = sel.notNullInfo
1875
+ if cases1.nonEmpty then nnInfo = nnInfo .seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
1876
+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nnInfo )
1877
1877
}
1878
1878
1879
1879
def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType : Type , pt : Type )(using Context ): List [CaseDef ] =
@@ -2053,7 +2053,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2053
2053
val capabilityProof = caughtExceptions.reduce(OrType (_, _, true ))
2054
2054
untpd.Block (makeCanThrow(capabilityProof), expr)
2055
2055
2056
- def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try = {
2056
+ def typedTry (tree : untpd.Try , pt : Type )(using Context ): Try =
2057
+ var nnInfo = NotNullInfo .empty
2057
2058
val expr2 :: cases2x = harmonic(harmonize, pt) {
2058
2059
// We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2059
2060
// uses the types of patterns in `tree.cases` to determine the capabilities.
@@ -2065,25 +2066,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2065
2066
val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef (_)(body = EmptyTree ))
2066
2067
val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree , defn.ThrowableType , WildcardType )
2067
2068
val expr1 = typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
2068
- val casesCtx = ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
2069
+
2070
+ // Since we don't know at which point the the exception is thrown in the body,
2071
+ // we have to collect any reference that is once retracted.
2072
+ nnInfo = expr1.notNullInfo.retractedInfo
2073
+
2074
+ val casesCtx = ctx.addNotNullInfo(nnInfo)
2069
2075
val cases1 = typedCases(tree.cases, EmptyTree , defn.ThrowableType , pt.dropIfProto)(using casesCtx)
2070
2076
expr1 :: cases1
2071
2077
}: @ unchecked
2072
2078
val cases2 = cases2x.asInstanceOf [List [CaseDef ]]
2073
2079
2074
- // Since we don't know at which point the the exception is thrown in the body,
2075
- // we have to collect any reference that is once retracted.
2076
- var nni = expr2.notNullInfo.onceRetractedInfo
2077
2080
// It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
2078
2081
// Therefore, the code in the finallizer and after the try block can only rely on the retracted
2079
2082
// info from the cases' body.
2080
- if cases2.nonEmpty then nni = nni.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
2081
-
2082
- val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nni))
2083
- nni = nni.seq(finalizer1.notNullInfo)
2083
+ if cases2.nonEmpty then
2084
+ nnInfo = nnInfo.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
2084
2085
2085
- assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nni)
2086
- }
2086
+ val finalizer1 = typed(tree.finalizer, defn.UnitType )(using ctx.addNotNullInfo(nnInfo))
2087
+ nnInfo = nnInfo.seq(finalizer1.notNullInfo)
2088
+ assignType(cpy.Try (tree)(expr2, cases2, finalizer1), expr2, cases2).withNotNullInfo(nnInfo)
2087
2089
2088
2090
def typedTry (tree : untpd.ParsedTry , pt : Type )(using Context ): Try =
2089
2091
val cases : List [untpd.CaseDef ] = tree.handler match
0 commit comments