@@ -570,10 +570,19 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
570
570
if ((skipped2 eq tp2) || ! Config .fastPathForRefinedSubtype)
571
571
tp1 match {
572
572
case tp1 : AndType =>
573
- // Delay calling `compareRefinedSlow` because looking up a member
574
- // of an `AndType` can lead to a cascade of subtyping checks
575
- // This twist is needed to make collection/generic/ParFactory.scala compile
576
- fourthTry || compareRefinedSlow
573
+ // TODO: this should really be an in depth analysis whether LHS contains
574
+ // an AndType, or has an AndType as bound. What matters is to predict
575
+ // whether we will be forced into an either later on.
576
+ tp2.parent match
577
+ case _ : RefinedType | _ : AndType =>
578
+ // maximally decompose RHS to limit the bad effects of the `either` that is necessary
579
+ // since LHS is an AndType
580
+ recur(tp1, decomposeRefinements(tp2, Nil ))
581
+ case _ =>
582
+ // Delay calling `compareRefinedSlow` because looking up a member
583
+ // of an `AndType` can lead to a cascade of subtyping checks
584
+ // This twist is needed to make collection/generic/ParFactory.scala compile
585
+ fourthTry || compareRefinedSlow
577
586
case tp1 : HKTypeLambda =>
578
587
// HKTypeLambdas do not have members.
579
588
fourthTry
@@ -1691,6 +1700,15 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1691
1700
else op2
1692
1701
end necessaryEither
1693
1702
1703
+ /** Decompose into conjunction of types each of which has only a single refinement */
1704
+ def decomposeRefinements (tp : Type , refines : List [(Name , Type )]): Type = tp match
1705
+ case RefinedType (parent, rname, rinfo) =>
1706
+ decomposeRefinements(parent, (rname, rinfo) :: refines)
1707
+ case AndType (tp1, tp2) =>
1708
+ AndType (decomposeRefinements(tp1, refines), decomposeRefinements(tp2, refines))
1709
+ case _ =>
1710
+ refines.map(RefinedType (tp, _, _): Type ).reduce(AndType (_, _))
1711
+
1694
1712
/** Does type `tp1` have a member with name `name` whose normalized type is a subtype of
1695
1713
* the normalized type of the refinement `tp2`?
1696
1714
* Normalization is as follows: If `tp2` contains a skolem to its refinement type,
0 commit comments