Skip to content

Commit 2644e15

Browse files
committed
Address review suggestions
1 parent a201437 commit 2644e15

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,34 +1781,30 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
17811781
else if (!tp2.exists) tp2
17821782
else if tp1.isAny && !tp2.isLambdaSub || tp1.isAnyKind || tp2.isRef(NothingClass) then tp1
17831783
else if tp2.isAny && !tp1.isLambdaSub || tp2.isAnyKind || tp1.isRef(NothingClass) then tp2
1784-
else tp1 match
1785-
case tp1: LazyRef => lub(tp1.ref, tp2)
1786-
case _ => tp2 match
1787-
case tp2: LazyRef => lub(tp1, tp2.ref)
1788-
case _ =>
1789-
def mergedLub: Type = {
1790-
val atoms1 = tp1.atoms(widenOK = true)
1791-
if (atoms1.nonEmpty && !widenInUnions) {
1792-
val atoms2 = tp2.atoms(widenOK = true)
1793-
if (atoms2.nonEmpty) {
1794-
if (atoms1.subsetOf(atoms2)) return tp2
1795-
if (atoms2.subsetOf(atoms1)) return tp1
1796-
if ((atoms1 & atoms2).isEmpty) return orType(tp1, tp2)
1797-
}
1798-
}
1799-
val t1 = mergeIfSuper(tp1, tp2, canConstrain)
1800-
if (t1.exists) return t1
1784+
else
1785+
def mergedLub(tp1: Type, tp2: Type): Type = {
1786+
val atoms1 = tp1.atoms(widenOK = true)
1787+
if (atoms1.nonEmpty && !widenInUnions) {
1788+
val atoms2 = tp2.atoms(widenOK = true)
1789+
if (atoms2.nonEmpty) {
1790+
if (atoms1.subsetOf(atoms2)) return tp2
1791+
if (atoms2.subsetOf(atoms1)) return tp1
1792+
if ((atoms1 & atoms2).isEmpty) return orType(tp1, tp2)
1793+
}
1794+
}
1795+
val t1 = mergeIfSuper(tp1, tp2, canConstrain)
1796+
if (t1.exists) return t1
18011797

1802-
val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1803-
if (t2.exists) return t2
1798+
val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1799+
if (t2.exists) return t2
18041800

1805-
def widen(tp: Type) = if (widenInUnions) tp.widen else tp.widenIfUnstable
1806-
val tp1w = widen(tp1)
1807-
val tp2w = widen(tp2)
1808-
if ((tp1 ne tp1w) || (tp2 ne tp2w)) lub(tp1w, tp2w)
1809-
else orType(tp1w, tp2w) // no need to check subtypes again
1810-
}
1811-
mergedLub
1801+
def widen(tp: Type) = if (widenInUnions) tp.widen else tp.widenIfUnstable
1802+
val tp1w = widen(tp1)
1803+
val tp2w = widen(tp2)
1804+
if ((tp1 ne tp1w) || (tp2 ne tp2w)) lub(tp1w, tp2w)
1805+
else orType(tp1w, tp2w) // no need to check subtypes again
1806+
}
1807+
mergedLub(tp1.stripLazyRef, tp2.stripLazyRef)
18121808
}
18131809

18141810
/** The least upper bound of a list of types */

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,14 +1044,15 @@ object Types {
10441044
case _ => this
10451045
}
10461046

1047-
/** Strip PolyType prefix */
1047+
/** Strip PolyType prefixes */
10481048
def stripPoly(implicit ctx: Context): Type = this match {
10491049
case tp: PolyType => tp.resType.stripPoly
10501050
case _ => this
10511051
}
10521052

1053+
/** Strip LazyRef wrappers */
10531054
def stripLazyRef(given Context): Type = this match
1054-
case lzy: LazyRef => lzy.ref
1055+
case lzy: LazyRef => lzy.ref.stripLazyRef
10551056
case _ => this
10561057

10571058
/** Widen from singleton type to its underlying non-singleton
@@ -1170,7 +1171,7 @@ object Types {
11701171
* these types as a set, otherwise the empty set.
11711172
* Overridden and cached in OrType.
11721173
* @param widenOK If type proxies that are upperbounded by types with atoms
1173-
* have the same atoms.
1174+
* have the same atoms.
11741175
*/
11751176
def atoms(widenOK: Boolean = false)(implicit ctx: Context): Set[Type] = dealias match {
11761177
case tp: SingletonType =>
@@ -4325,7 +4326,7 @@ object Types {
43254326
if ((prefix eq this.prefix) && (classParents eq this.classParents) && (decls eq this.decls) && (selfInfo eq this.selfInfo)) this
43264327
else newLikeThis(prefix, classParents, decls, selfInfo)
43274328

4328-
/** If this class has opqque type alias members, a new class info
4329+
/** If this class has opaque type alias members, a new class info
43294330
* with their aliases added as refinements to the self type of the class.
43304331
* Otherwise, this classInfo.
43314332
* If there are opaque alias members, updates `cls` to have `Opaque` flag as a side effect.

0 commit comments

Comments
 (0)