Skip to content

Commit b956839

Browse files
committed
Lub MatchTypeTree case body types and store as the inferred bound
[Cherry-picked c25edde][modified]
1 parent 7db2746 commit b956839

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -978,17 +978,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
978978
if (tp1 ne tp1norm) recur(tp1norm, tp2)
979979
else either(recur(tp11, tp2), recur(tp12, tp2))
980980
case tp1: MatchType =>
981-
def compareUpper =
982-
val lub1 = tp1.cases.foldLeft(defn.NothingType: Type): (acc, case1) =>
983-
if acc.exists then
984-
val rhs = case1.resultType match { case defn.MatchCase(_, body) => body }
985-
val isRecursive = rhs.existsPart(_.isInstanceOf[LazyRef])
986-
if isRecursive then NoType else lub(acc, rhs)
987-
else acc
988-
if lub1.exists then
989-
recur(lub1, tp2)
990-
else
991-
recur(tp1.underlying, tp2)
992981
def compareMatch = tp2 match {
993982
case tp2: MatchType =>
994983
isSameType(tp1.scrutinee, tp2.scrutinee) &&

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
22782278
report.error(MatchTypeScrutineeCannotBeHigherKinded(sel1Tpe), sel1.srcPos)
22792279
val pt1 = if (bound1.isEmpty) pt else bound1.tpe
22802280
val cases1 = tree.cases.mapconserve(typedTypeCase(_, sel1Tpe, pt1))
2281-
assignType(cpy.MatchTypeTree(tree)(bound1, sel1, cases1), bound1, sel1, cases1)
2281+
val bound2 = if tree.bound.isEmpty then
2282+
val lub = cases1.foldLeft(defn.NothingType: Type): (acc, case1) =>
2283+
if !acc.exists then NoType
2284+
else if case1.body.tpe.existsPart(_.isInstanceOf[LazyRef]) then NoType
2285+
else acc | TypeOps.avoid(case1.body.tpe, patVars(case1))
2286+
if lub.exists then TypeTree(lub, inferred = true)
2287+
else bound1
2288+
else bound1
2289+
assignType(cpy.MatchTypeTree(tree)(bound2, sel1, cases1), bound2, sel1, cases1)
22822290
}
22832291

22842292
def typedByNameTypeTree(tree: untpd.ByNameTypeTree)(using Context): ByNameTypeTree = tree.result match

0 commit comments

Comments
 (0)