@@ -1725,10 +1725,14 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
1725
1725
else if tp1.isAny && ! tp2.isLambdaSub || tp1.isAnyKind || tp2.isRef(NothingClass ) then tp2
1726
1726
else if tp2.isAny && ! tp1.isLambdaSub || tp2.isAnyKind || tp1.isRef(NothingClass ) then tp1
1727
1727
else tp2 match { // normalize to disjunctive normal form if possible.
1728
+ case tp2 : LazyRef =>
1729
+ glb(tp1, tp2.ref)
1728
1730
case OrType (tp21, tp22) =>
1729
1731
tp1 & tp21 | tp1 & tp22
1730
1732
case _ =>
1731
1733
tp1 match {
1734
+ case tp1 : LazyRef =>
1735
+ glb(tp1.ref, tp2)
1732
1736
case OrType (tp11, tp12) =>
1733
1737
tp11 & tp2 | tp12 & tp2
1734
1738
case _ =>
@@ -1775,31 +1779,34 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
1775
1779
else if (! tp2.exists) tp2
1776
1780
else if tp1.isAny && ! tp2.isLambdaSub || tp1.isAnyKind || tp2.isRef(NothingClass ) then tp1
1777
1781
else if tp2.isAny && ! tp1.isLambdaSub || tp2.isAnyKind || tp1.isRef(NothingClass ) then tp2
1778
- else {
1779
- def mergedLub : Type = {
1780
- val atoms1 = tp1.atoms
1781
- if (atoms1.nonEmpty && ! widenInUnions) {
1782
- val atoms2 = tp2.atoms
1783
- if (atoms2.nonEmpty) {
1784
- if (atoms1.subsetOf(atoms2)) return tp2
1785
- if (atoms2.subsetOf(atoms1)) return tp1
1786
- if ((atoms1 & atoms2).isEmpty) return orType(tp1, tp2)
1787
- }
1788
- }
1789
- val t1 = mergeIfSuper(tp1, tp2, canConstrain)
1790
- if (t1.exists) return t1
1782
+ else tp1 match
1783
+ case tp1 : LazyRef => lub(tp1.ref, tp2)
1784
+ case _ => tp2 match
1785
+ case tp2 : LazyRef => lub(tp1, tp2.ref)
1786
+ case _ =>
1787
+ def mergedLub : Type = {
1788
+ val atoms1 = tp1.atoms
1789
+ if (atoms1.nonEmpty && ! widenInUnions) {
1790
+ val atoms2 = tp2.atoms
1791
+ if (atoms2.nonEmpty) {
1792
+ if (atoms1.subsetOf(atoms2)) return tp2
1793
+ if (atoms2.subsetOf(atoms1)) return tp1
1794
+ if ((atoms1 & atoms2).isEmpty) return orType(tp1, tp2)
1795
+ }
1796
+ }
1797
+ val t1 = mergeIfSuper(tp1, tp2, canConstrain)
1798
+ if (t1.exists) return t1
1791
1799
1792
- val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1793
- if (t2.exists) return t2
1800
+ val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1801
+ if (t2.exists) return t2
1794
1802
1795
- def widen (tp : Type ) = if (widenInUnions) tp.widen else tp.widenIfUnstable
1796
- val tp1w = widen(tp1)
1797
- val tp2w = widen(tp2)
1798
- if ((tp1 ne tp1w) || (tp2 ne tp2w)) lub(tp1w, tp2w)
1799
- else orType(tp1w, tp2w) // no need to check subtypes again
1800
- }
1801
- mergedLub
1802
- }
1803
+ def widen (tp : Type ) = if (widenInUnions) tp.widen else tp.widenIfUnstable
1804
+ val tp1w = widen(tp1)
1805
+ val tp2w = widen(tp2)
1806
+ if ((tp1 ne tp1w) || (tp2 ne tp2w)) lub(tp1w, tp2w)
1807
+ else orType(tp1w, tp2w) // no need to check subtypes again
1808
+ }
1809
+ mergedLub
1803
1810
}
1804
1811
1805
1812
/** The least upper bound of a list of types */
0 commit comments