@@ -1543,9 +1543,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15431543 def thenPathInfo = cond1.notNullInfoIf(true ).seq(result.thenp.notNullInfo)
15441544 def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
15451545 result.withNotNullInfo(
1546- if result.thenp.tpe.isRef(defn. NothingClass ) then
1546+ if result.thenp.tpe.isNothingType then
15471547 elsePathInfo.withRetracted(thenPathInfo)
1548- else if result.elsep.tpe.isRef(defn. NothingClass ) then
1548+ else if result.elsep.tpe.isNothingType then
15491549 thenPathInfo.withRetracted(elsePathInfo)
15501550 else thenPathInfo.alt(elsePathInfo)
15511551 )
@@ -2134,20 +2134,28 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
21342134 case1
21352135 }
21362136 .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))
21402139 }
21412140
21422141 // Overridden in InlineTyper for inline matches
21432142 def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
21442143 val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
21452144 .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))
21492147 }
21502148
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+
21512159 def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType0 : Type , pt : Type )(using Context ): List [CaseDef ] =
21522160 var caseCtx = ctx
21532161 var wideSelType = wideSelType0
0 commit comments