@@ -1334,9 +1334,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1334
1334
def thenPathInfo = cond1.notNullInfoIf(true ).seq(result.thenp.notNullInfo)
1335
1335
def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
1336
1336
result.withNotNullInfo(
1337
- if result.thenp.tpe.isRef(defn. NothingClass ) then
1337
+ if result.thenp.tpe.isNothingType then
1338
1338
elsePathInfo.withRetracted(thenPathInfo)
1339
- else if result.elsep.tpe.isRef(defn. NothingClass ) then
1339
+ else if result.elsep.tpe.isNothingType then
1340
1340
thenPathInfo.withRetracted(elsePathInfo)
1341
1341
else thenPathInfo.alt(elsePathInfo)
1342
1342
)
@@ -1862,20 +1862,28 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1862
1862
case1
1863
1863
}
1864
1864
.asInstanceOf [List [CaseDef ]]
1865
- var nni = sel.notNullInfo
1866
- if cases1.nonEmpty then nni = nni.seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
1867
- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).cast(pt).withNotNullInfo(nni)
1865
+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1).cast(pt)
1866
+ .withNotNullInfo(notNullInfoFromCases(sel.notNullInfo, cases1))
1868
1867
}
1869
1868
1870
1869
// Overridden in InlineTyper for inline matches
1871
1870
def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
1872
1871
val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
1873
1872
.asInstanceOf [List [CaseDef ]]
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)
1873
+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1)
1874
+ .withNotNullInfo(notNullInfoFromCases(sel.notNullInfo, cases1))
1877
1875
}
1878
1876
1877
+ private def notNullInfoFromCases (initInfo : NotNullInfo , cases : List [CaseDef ])(using Context ): NotNullInfo =
1878
+ var nnInfo = initInfo
1879
+ if cases.nonEmpty then
1880
+ val (nothingCases, normalCases) = cases.partition(_.body.tpe.isNothingType)
1881
+ nnInfo = nothingCases.foldLeft(nnInfo):
1882
+ (nni, c) => nni.withRetracted(c.notNullInfo)
1883
+ if normalCases.nonEmpty then
1884
+ nnInfo = nnInfo.seq(normalCases.map(_.notNullInfo).reduce(_.alt(_)))
1885
+ nnInfo
1886
+
1879
1887
def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType : Type , pt : Type )(using Context ): List [CaseDef ] =
1880
1888
var caseCtx = ctx
1881
1889
cases.mapconserve { cas =>
0 commit comments