@@ -1726,31 +1726,36 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
1726
1726
* @note We do not admit singleton types in or-types as lubs.
1727
1727
*/
1728
1728
def lub (tp1 : Type , tp2 : Type , canConstrain : Boolean = false ): Type = /* >|>*/ trace(s " lub( ${tp1.show}, ${tp2.show}, canConstrain= $canConstrain) " , subtyping, show = true ) /* <|<*/ {
1729
- if (tp1 eq tp2) return tp1
1730
- if (! tp1.exists) return tp1
1731
- if (! tp2.exists) return tp2
1732
- if ((tp1 isRef AnyClass ) || (tp1 isRef AnyKindClass ) || (tp2 isRef NothingClass )) return tp1
1733
- if ((tp2 isRef AnyClass ) || (tp2 isRef AnyKindClass ) || (tp1 isRef NothingClass )) return tp2
1734
- val atoms1 = tp1.atoms
1735
- if (atoms1.nonEmpty && ! widenInUnions) {
1736
- val atoms2 = tp2.atoms
1737
- if (atoms2.nonEmpty) {
1738
- if (atoms1.subsetOf(atoms2)) return tp2
1739
- if (atoms2.subsetOf(atoms1)) return tp1
1740
- if ((atoms1 & atoms2).isEmpty) return orType(tp1, tp2)
1741
- }
1742
- }
1743
- val t1 = mergeIfSuper(tp1, tp2, canConstrain)
1744
- if (t1.exists) return t1
1729
+ if (tp1 eq tp2) tp1
1730
+ else if (! tp1.exists) tp1
1731
+ else if (! tp2.exists) tp2
1732
+ else if ((tp1 isRef AnyClass ) || (tp1 isRef AnyKindClass ) || (tp2 isRef NothingClass )) tp1
1733
+ else if ((tp2 isRef AnyClass ) || (tp2 isRef AnyKindClass ) || (tp1 isRef NothingClass )) tp2
1734
+ else {
1735
+ def mergedLub : Type = {
1736
+ val atoms1 = tp1.atoms
1737
+ if (atoms1.nonEmpty && ! widenInUnions) {
1738
+ val atoms2 = tp2.atoms
1739
+ if (atoms2.nonEmpty) {
1740
+ if (atoms1.subsetOf(atoms2)) return tp2
1741
+ if (atoms2.subsetOf(atoms1)) return tp1
1742
+ if ((atoms1 & atoms2).isEmpty) return orType(tp1, tp2)
1743
+ }
1744
+ }
1745
+ val t1 = mergeIfSuper(tp1, tp2, canConstrain)
1746
+ if (t1.exists) return t1
1745
1747
1746
- val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1747
- if (t2.exists) return t2
1748
+ val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1749
+ if (t2.exists) return t2
1748
1750
1749
- def widen (tp : Type ) = if (widenInUnions) tp.widen else tp.widenIfUnstable
1750
- val tp1w = widen(tp1)
1751
- val tp2w = widen(tp2)
1752
- if ((tp1 ne tp1w) || (tp2 ne tp2w)) lub(tp1w, tp2w)
1753
- else orType(tp1w, tp2w) // no need to check subtypes again
1751
+ def widen (tp : Type ) = if (widenInUnions) tp.widen else tp.widenIfUnstable
1752
+ val tp1w = widen(tp1)
1753
+ val tp2w = widen(tp2)
1754
+ if ((tp1 ne tp1w) || (tp2 ne tp2w)) lub(tp1w, tp2w)
1755
+ else orType(tp1w, tp2w) // no need to check subtypes again
1756
+ }
1757
+ mergedLub
1758
+ }
1754
1759
}
1755
1760
1756
1761
/** The least upper bound of a list of types */
0 commit comments