Skip to content

Commit d2337e3

Browse files
committed
Don't merge T and => T in lubs and glbs
Align lub/glb with the changes to subtyping.
1 parent 728225f commit d2337e3

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ object Denotations {
518518
val info1 = denot1.info
519519
val info2 = denot2.info
520520
val sameSym = sym1 eq sym2
521-
if (sameSym && (info1 frozen_<:< info2)) denot2
522-
else if (sameSym && (info2 frozen_<:< info1)) denot1
521+
if (sameSym && (info1.widenExpr frozen_<:< info2.widenExpr)) denot2
522+
else if (sameSym && (info2.widenExpr frozen_<:< info1.widenExpr)) denot1
523523
else {
524524
val jointSym =
525525
if (sameSym) sym1
@@ -586,9 +586,11 @@ object Denotations {
586586
(for ((name1, name2, idx) <- (tp1.paramNames, tp2.paramNames, tp1.paramNames.indices).zipped)
587587
yield if (name1 == name2) name1 else tp1.companion.syntheticParamName(idx)).toList
588588

589-
/** Normally, `tp1 & tp2`. Special cases for matching methods and classes, with
590-
* the possibility of raising a merge error.
591-
*/
589+
/** Normally, `tp1 & tp2`.
590+
* Special cases for matching methods and classes, with
591+
* the possibility of raising a merge error.
592+
* Special handling of ExprTypes, where mixed intersections widen the ExprType away.
593+
*/
592594
def infoMeet(tp1: Type, tp2: Type, sym1: Symbol, sym2: Symbol, safeIntersection: Boolean)(implicit ctx: Context): Type = {
593595
if (tp1 eq tp2) tp1
594596
else tp1 match {
@@ -645,9 +647,13 @@ object Denotations {
645647
case _ =>
646648
mergeConflict(sym1, sym2, tp1, tp2)
647649
}
648-
650+
case ExprType(rtp1) =>
651+
tp2 match {
652+
case ExprType(rtp2) ExprType(rtp1 & rtp2)
653+
case _ => rtp1 & tp2
654+
}
649655
case _ =>
650-
try tp1.widenExpr & tp2.widenExpr
656+
try tp1 & tp2.widenExpr
651657
catch {
652658
case ex: Throwable =>
653659
println(i"error for meet: $tp1 &&& $tp2, ${tp1.getClass}, ${tp2.getClass}")
@@ -656,9 +662,11 @@ object Denotations {
656662
}
657663
}
658664

659-
/** Normally, `tp1 | tp2`. Special cases for matching methods and classes, with
660-
* the possibility of raising a merge error.
661-
*/
665+
/** Normally, `tp1 | tp2`.
666+
* Special cases for matching methods and classes, with
667+
* the possibility of raising a merge error.
668+
* Special handling of ExprTypes, where mixed unions widen the ExprType away.
669+
*/
662670
def infoJoin(tp1: Type, tp2: Type, sym1: Symbol, sym2: Symbol)(implicit ctx: Context): Type = tp1 match {
663671
case tp1: TypeBounds =>
664672
tp2 match {
@@ -697,8 +705,13 @@ object Denotations {
697705
case _ =>
698706
mergeConflict(sym1, sym2, tp1, tp2)
699707
}
708+
case ExprType(rtp1) =>
709+
tp2 match {
710+
case ExprType(rtp2) => ExprType(rtp1 | rtp2)
711+
case _ => rtp1 | tp2
712+
}
700713
case _ =>
701-
tp1 | tp2
714+
tp1 | tp2.widenExpr
702715
}
703716

704717
/** A non-overloaded denotation */

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
17571757
case ExprType(rt2) =>
17581758
ExprType(rt1 & rt2)
17591759
case _ =>
1760-
rt1 & tp2
1760+
NoType
17611761
}
17621762
case tp1: TypeVar if tp1.isInstantiated =>
17631763
tp1.underlying & tp2
@@ -1777,7 +1777,12 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
17771777
*/
17781778
private def distributeOr(tp1: Type, tp2: Type): Type = tp1 match {
17791779
case ExprType(rt1) =>
1780-
ExprType(rt1 | tp2.widenExpr)
1780+
tp2 match {
1781+
case ExprType(rt2) =>
1782+
ExprType(rt1 | rt2)
1783+
case _ =>
1784+
NoType
1785+
}
17811786
case tp1: TypeVar if tp1.isInstantiated =>
17821787
tp1.underlying | tp2
17831788
case tp1: AnnotatedType if !tp1.isRefining =>

0 commit comments

Comments
 (0)