@@ -1543,9 +1543,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1543
1543
def thenPathInfo = cond1.notNullInfoIf(true ).seq(result.thenp.notNullInfo)
1544
1544
def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
1545
1545
result.withNotNullInfo(
1546
- if result.thenp.tpe.isRef(defn. NothingClass ) then
1546
+ if result.thenp.tpe.isNothingType then
1547
1547
elsePathInfo.withRetracted(thenPathInfo)
1548
- else if result.elsep.tpe.isRef(defn. NothingClass ) then
1548
+ else if result.elsep.tpe.isNothingType then
1549
1549
thenPathInfo.withRetracted(elsePathInfo)
1550
1550
else thenPathInfo.alt(elsePathInfo)
1551
1551
)
@@ -2134,20 +2134,28 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2134
2134
case1
2135
2135
}
2136
2136
.asInstanceOf [List [CaseDef ]]
2137
- var nni = sel.notNullInfo
2138
- if cases1.nonEmpty then nni = nni.seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2139
- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).cast(pt).withNotNullInfo(nni)
2137
+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1).cast(pt)
2138
+ .withNotNullInfo(notNullInfoFromCases(sel.notNullInfo, cases1))
2140
2139
}
2141
2140
2142
2141
// Overridden in InlineTyper for inline matches
2143
2142
def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
2144
2143
val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
2145
2144
.asInstanceOf [List [CaseDef ]]
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)
2145
+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1)
2146
+ .withNotNullInfo(notNullInfoFromCases(sel.notNullInfo, cases1))
2149
2147
}
2150
2148
2149
+ private def notNullInfoFromCases (initInfo : NotNullInfo , cases : List [CaseDef ])(using Context ): NotNullInfo =
2150
+ var nnInfo = initInfo
2151
+ if cases.nonEmpty then
2152
+ val (nothingCases, normalCases) = cases.partition(_.body.tpe.isNothingType)
2153
+ nnInfo = nothingCases.foldLeft(nnInfo):
2154
+ (nni, c) => nni.withRetracted(c.notNullInfo)
2155
+ if normalCases.nonEmpty then
2156
+ nnInfo = nnInfo.seq(normalCases.map(_.notNullInfo).reduce(_.alt(_)))
2157
+ nnInfo
2158
+
2151
2159
def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType0 : Type , pt : Type )(using Context ): List [CaseDef ] =
2152
2160
var caseCtx = ctx
2153
2161
var wideSelType = wideSelType0
0 commit comments