@@ -1552,9 +1552,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15521552 def thenPathInfo = cond1.notNullInfoIf(true ).seq(result.thenp.notNullInfo)
15531553 def elsePathInfo = cond1.notNullInfoIf(false ).seq(result.elsep.notNullInfo)
15541554 result.withNotNullInfo(
1555- if result.thenp.tpe.isRef(defn. NothingClass ) then
1555+ if result.thenp.tpe.isNothingType then
15561556 elsePathInfo.withRetracted(thenPathInfo)
1557- else if result.elsep.tpe.isRef(defn. NothingClass ) then
1557+ else if result.elsep.tpe.isNothingType then
15581558 thenPathInfo.withRetracted(elsePathInfo)
15591559 else thenPathInfo.alt(elsePathInfo)
15601560 )
@@ -2141,20 +2141,28 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
21412141 case1
21422142 }
21432143 .asInstanceOf [List [CaseDef ]]
2144- var nni = sel.notNullInfo
2145- if cases1.nonEmpty then nni = nni.seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2146- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).cast(pt).withNotNullInfo(nni)
2144+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1).cast(pt)
2145+ .withNotNullInfo(notNullInfoFromCases(sel.notNullInfo, cases1))
21472146 }
21482147
21492148 // Overridden in InlineTyper for inline matches
21502149 def typedMatchFinish (tree : untpd.Match , sel : Tree , wideSelType : Type , cases : List [untpd.CaseDef ], pt : Type )(using Context ): Tree = {
21512150 val cases1 = harmonic(harmonize, pt)(typedCases(cases, sel, wideSelType, pt.dropIfProto))
21522151 .asInstanceOf [List [CaseDef ]]
2153- var nnInfo = sel.notNullInfo
2154- if cases1.nonEmpty then nnInfo = nnInfo.seq(cases1.map(_.notNullInfo).reduce(_.alt(_)))
2155- assignType(cpy.Match (tree)(sel, cases1), sel, cases1).withNotNullInfo(nnInfo)
2152+ assignType(cpy.Match (tree)(sel, cases1), sel, cases1)
2153+ .withNotNullInfo(notNullInfoFromCases(sel.notNullInfo, cases1))
21562154 }
21572155
2156+ private def notNullInfoFromCases (initInfo : NotNullInfo , cases : List [CaseDef ])(using Context ): NotNullInfo =
2157+ var nnInfo = initInfo
2158+ if cases.nonEmpty then
2159+ val (nothingCases, normalCases) = cases.partition(_.body.tpe.isNothingType)
2160+ nnInfo = nothingCases.foldLeft(nnInfo):
2161+ (nni, c) => nni.withRetracted(c.notNullInfo)
2162+ if normalCases.nonEmpty then
2163+ nnInfo = nnInfo.seq(normalCases.map(_.notNullInfo).reduce(_.alt(_)))
2164+ nnInfo
2165+
21582166 def typedCases (cases : List [untpd.CaseDef ], sel : Tree , wideSelType0 : Type , pt : Type )(using Context ): List [CaseDef ] =
21592167 var caseCtx = ctx
21602168 var wideSelType = wideSelType0
0 commit comments