@@ -2460,7 +2460,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2460
2460
2461
2461
/** If the range `tp1..tp2` consist of a single type, that type, otherwise NoType`.
2462
2462
* This is the case if `tp1 =:= tp2`, but also if `tp1 <:< tp2`, `tp1` is a singleton type,
2463
- * and `tp2` derives from `scala.Singleton` (or vice-versa). Examples of the latter case:
2463
+ * and `tp2` derives from `scala.Singleton` and `sourceVersion.enablesDistributeAnd` (or vice-versa).
2464
+ * Examples of the latter case:
2464
2465
*
2465
2466
* "name".type .. Singleton
2466
2467
* "name".type .. String & Singleton
@@ -2473,8 +2474,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2473
2474
def isSingletonBounds (lo : Type , hi : Type ) =
2474
2475
lo.isSingleton && hi.derivesFrom(defn.SingletonClass ) && isSubTypeWhenFrozen(lo, hi)
2475
2476
if (isSameTypeWhenFrozen(tp1, tp2)) tp1
2476
- else if (isSingletonBounds(tp1, tp2)) tp1
2477
- else if (isSingletonBounds(tp2, tp1)) tp2
2477
+ else if sourceVersion.enablesDistributeAnd then
2478
+ if (isSingletonBounds(tp1, tp2)) tp1
2479
+ else if (isSingletonBounds(tp2, tp1)) tp2
2480
+ else NoType
2478
2481
else NoType
2479
2482
}
2480
2483
@@ -2771,7 +2774,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2771
2774
* @pre !(tp1 <: tp2) && !(tp2 <:< tp1) -- these cases were handled before
2772
2775
*/
2773
2776
private def distributeAnd (tp1 : Type , tp2 : Type ): Type = tp1 match {
2774
- case tp1 @ AppliedType (tycon1, args1) =>
2777
+ case tp1 @ AppliedType (tycon1, args1) if sourceVersion.enablesDistributeAnd =>
2775
2778
tp2 match {
2776
2779
case AppliedType (tycon2, args2)
2777
2780
if tycon1.typeSymbol == tycon2.typeSymbol && tycon1 =:= tycon2 =>
@@ -2819,8 +2822,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2819
2822
}
2820
2823
2821
2824
/** Try to distribute `|` inside type, detect and handle conflicts
2822
- * Note that, unlike for `&`, a disjunction cannot be pushed into
2823
- * a refined or applied type. Example:
2825
+ * Note that a disjunction cannot be pushed into a refined or applied type. Example:
2824
2826
*
2825
2827
* List[T] | List[U] is not the same as List[T | U].
2826
2828
*
0 commit comments