@@ -1727,10 +1727,14 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
17271727 else if tp1.isAny && ! tp2.isLambdaSub || tp1.isAnyKind || tp2.isRef(NothingClass ) then tp2
17281728 else if tp2.isAny && ! tp1.isLambdaSub || tp2.isAnyKind || tp1.isRef(NothingClass ) then tp1
17291729 else tp2 match { // normalize to disjunctive normal form if possible.
1730+ case tp2 : LazyRef =>
1731+ glb(tp1, tp2.ref)
17301732 case OrType (tp21, tp22) =>
17311733 tp1 & tp21 | tp1 & tp22
17321734 case _ =>
17331735 tp1 match {
1736+ case tp1 : LazyRef =>
1737+ glb(tp1.ref, tp2)
17341738 case OrType (tp11, tp12) =>
17351739 tp11 & tp2 | tp12 & tp2
17361740 case _ =>
@@ -1777,31 +1781,34 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
17771781 else if (! tp2.exists) tp2
17781782 else if tp1.isAny && ! tp2.isLambdaSub || tp1.isAnyKind || tp2.isRef(NothingClass ) then tp1
17791783 else if tp2.isAny && ! tp1.isLambdaSub || tp2.isAnyKind || tp1.isRef(NothingClass ) then tp2
1780- else {
1781- def mergedLub : Type = {
1782- val atoms1 = tp1.atoms(widenOK = true )
1783- if (atoms1.nonEmpty && ! widenInUnions) {
1784- val atoms2 = tp2.atoms(widenOK = true )
1785- if (atoms2.nonEmpty) {
1786- if (atoms1.subsetOf(atoms2)) return tp2
1787- if (atoms2.subsetOf(atoms1)) return tp1
1788- if ((atoms1 & atoms2).isEmpty) return orType(tp1, tp2)
1789- }
1790- }
1791- val t1 = mergeIfSuper(tp1, tp2, canConstrain)
1792- if (t1.exists) return t1
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
17931801
1794- val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1795- if (t2.exists) return t2
1802+ val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1803+ if (t2.exists) return t2
17961804
1797- def widen (tp : Type ) = if (widenInUnions) tp.widen else tp.widenIfUnstable
1798- val tp1w = widen(tp1)
1799- val tp2w = widen(tp2)
1800- if ((tp1 ne tp1w) || (tp2 ne tp2w)) lub(tp1w, tp2w)
1801- else orType(tp1w, tp2w) // no need to check subtypes again
1802- }
1803- mergedLub
1804- }
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
18051812 }
18061813
18071814 /** The least upper bound of a list of types */
0 commit comments