@@ -417,6 +417,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
417
417
if (tp11.stripTypeVar eq tp12.stripTypeVar) recur(tp11, tp2)
418
418
else thirdTry
419
419
case tp1 @ OrType (tp11, tp12) =>
420
+
420
421
def joinOK = tp2.dealiasKeepRefiningAnnots match {
421
422
case tp2 : AppliedType if ! tp2.tycon.typeSymbol.isClass =>
422
423
// If we apply the default algorithm for `A[X] | B[Y] <: C[Z]` where `C` is a
@@ -427,6 +428,12 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
427
428
case _ =>
428
429
false
429
430
}
431
+
432
+ def containsAnd (tp : Type ): Boolean = tp.dealiasKeepRefiningAnnots match
433
+ case tp : AndType => true
434
+ case OrType (tp1, tp2) => containsAnd(tp1) || containsAnd(tp2)
435
+ case _ => false
436
+
430
437
def widenOK =
431
438
(tp2.widenSingletons eq tp2) &&
432
439
(tp1.widenSingletons ne tp1) &&
@@ -435,7 +442,15 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
435
442
if (tp2.atoms.nonEmpty && canCompare(tp2.atoms))
436
443
tp1.atoms.nonEmpty && tp1.atoms.subsetOf(tp2.atoms)
437
444
else
438
- widenOK || joinOK || recur(tp11, tp2) && recur(tp12, tp2)
445
+ widenOK
446
+ || joinOK
447
+ || recur(tp11, tp2) && recur(tp12, tp2)
448
+ || containsAnd(tp1) && recur(tp1.join, tp2)
449
+ // An & on the left side loses information. Compensate by also trying the join.
450
+ // This is less ad-hoc than it looks since we produce joins in type inference,
451
+ // and then need to check that they are indeed supertypes of the original types
452
+ // under -Ycheck. Test case is i7965.scala.
453
+
439
454
case tp1 : MatchType =>
440
455
val reduced = tp1.reduced
441
456
if (reduced.exists) recur(reduced, tp2) else thirdTry
0 commit comments