@@ -440,18 +440,20 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
440440 (tp1.widenSingletons ne tp1) &&
441441 recur(tp1.widenSingletons, tp2)
442442
443- if (tp2.atoms().nonEmpty && canCompare(tp2.atoms()))
444- val atoms1 = tp1.atoms(widenOK = true )
445- atoms1.nonEmpty && atoms1.subsetOf(tp2.atoms())
446- else
447- widenOK
448- || joinOK
449- || recur(tp11, tp2) && recur(tp12, tp2)
450- || containsAnd(tp1) && recur(tp1.join, tp2)
451- // An & on the left side loses information. Compensate by also trying the join.
452- // This is less ad-hoc than it looks since we produce joins in type inference,
453- // and then need to check that they are indeed supertypes of the original types
454- // under -Ycheck. Test case is i7965.scala.
443+ tp2.atoms() match
444+ case Some (ts2) if canCompare(ts2) =>
445+ tp1.atoms(widenOK = true ) match
446+ case Some (ts1) => ts1.subsetOf(ts2)
447+ case none => false
448+ case _ =>
449+ widenOK
450+ || joinOK
451+ || recur(tp11, tp2) && recur(tp12, tp2)
452+ || containsAnd(tp1) && recur(tp1.join, tp2)
453+ // An & on the left side loses information. Compensate by also trying the join.
454+ // This is less ad-hoc than it looks since we produce joins in type inference,
455+ // and then need to check that they are indeed supertypes of the original types
456+ // under -Ycheck. Test case is i7965.scala.
455457
456458 case tp1 : MatchType =>
457459 val reduced = tp1.reduced
@@ -613,9 +615,13 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
613615 }
614616 compareTypeLambda
615617 case OrType (tp21, tp22) =>
616- if (tp2.atoms().nonEmpty && canCompare(tp2.atoms()))
617- val atoms1 = tp1.atoms(widenOK = true )
618- return atoms1.nonEmpty && atoms1.subsetOf(tp2.atoms()) || isSubType(tp1, NothingType )
618+ tp2.atoms() match
619+ case Some (ts2) if canCompare(ts2) =>
620+ val atomsFit = tp1.atoms(widenOK = true ) match
621+ case Some (ts1) => ts1.subsetOf(ts2)
622+ case none => false
623+ return atomsFit || isSubType(tp1, NothingType )
624+ case none =>
619625
620626 // The next clause handles a situation like the one encountered in i2745.scala.
621627 // We have:
@@ -1787,15 +1793,15 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
17871793 else if tp2.isAny && ! tp1.isLambdaSub || tp2.isAnyKind || tp1.isRef(NothingClass ) then tp2
17881794 else
17891795 def mergedLub (tp1 : Type , tp2 : Type ): 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- }
1796+ tp1.atoms(widenOK = true ) match
1797+ case Some (ts1) if ! widenInUnions =>
1798+ tp2.atoms(widenOK = true ) match
1799+ case Some (ts2) =>
1800+ if ts1 .subsetOf(ts2) then return tp2
1801+ if ts2 .subsetOf(ts1) then return tp1
1802+ if (ts1 & ts2 ).isEmpty then return orType(tp1, tp2)
1803+ case none =>
1804+ case none =>
17991805 val t1 = mergeIfSuper(tp1, tp2, canConstrain)
18001806 if (t1.exists) return t1
18011807
0 commit comments