@@ -2388,7 +2388,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2388
2388
case _ => false
2389
2389
}
2390
2390
2391
-
2392
2391
/** Are `tp1` and `tp2` provablyDisjoint types?
2393
2392
*
2394
2393
* `true` implies that we found a proof; uncertainty defaults to `false`.
@@ -2507,17 +2506,25 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2507
2506
case (_, tp2 : AndType ) =>
2508
2507
! (tp2 <:< tp1)
2509
2508
&& (provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1))
2509
+ case (tp1 : NamedType , _) if gadtBounds(tp1.symbol) != null =>
2510
+ provablyDisjoint(gadtBounds(tp1.symbol).hi, tp2) || provablyDisjoint(tp1.superType, tp2)
2511
+ case (_, tp2 : NamedType ) if gadtBounds(tp2.symbol) != null =>
2512
+ provablyDisjoint(tp1, gadtBounds(tp2.symbol).hi) || provablyDisjoint(tp1, tp2.superType)
2510
2513
case (tp1 : TypeProxy , tp2 : TypeProxy ) =>
2511
- provablyDisjoint(tp1.underlying , tp2) || provablyDisjoint(tp1, tp2.underlying )
2514
+ provablyDisjoint(matchTypeSuperType( tp1) , tp2) || provablyDisjoint(tp1, matchTypeSuperType( tp2) )
2512
2515
case (tp1 : TypeProxy , _) =>
2513
- provablyDisjoint(tp1.underlying , tp2)
2516
+ provablyDisjoint(matchTypeSuperType( tp1) , tp2)
2514
2517
case (_, tp2 : TypeProxy ) =>
2515
- provablyDisjoint(tp1, tp2.underlying )
2518
+ provablyDisjoint(tp1, matchTypeSuperType( tp2) )
2516
2519
case _ =>
2517
2520
false
2518
2521
}
2519
2522
}
2520
2523
2524
+ /** Restores the buggy match type reduction under -Yunsound-match-types. */
2525
+ private def matchTypeSuperType (tp : TypeProxy ): Type =
2526
+ if ctx.settings.YunsoundMatchTypes .value then tp.underlying else tp.superType
2527
+
2521
2528
protected def explainingTypeComparer = ExplainingTypeComparer (comparerContext)
2522
2529
protected def trackingTypeComparer = TrackingTypeComparer (comparerContext)
2523
2530
@@ -2757,34 +2764,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
2757
2764
case _ =>
2758
2765
cas
2759
2766
}
2760
- def widenAbstractTypes (tp : Type ): Type = new TypeMap {
2761
- var seen = Set [TypeParamRef ]()
2762
- def apply (tp : Type ) = tp match {
2763
- case tp : TypeRef =>
2764
- tp.info match {
2765
- case info : MatchAlias =>
2766
- mapOver(tp)
2767
- // TODO: We should follow the alias in this case, but doing so
2768
- // risks infinite recursion
2769
- case TypeBounds (lo, hi) =>
2770
- if (hi frozen_<:< lo) {
2771
- val alias = apply(lo)
2772
- if (alias ne lo) alias else mapOver(tp)
2773
- }
2774
- else WildcardType
2775
- case _ =>
2776
- mapOver(tp)
2777
- }
2778
- case tp : TypeLambda =>
2779
- val saved = seen
2780
- seen ++= tp.paramRefs
2781
- try mapOver(tp)
2782
- finally seen = saved
2783
- case tp : TypeVar if ! tp.isInstantiated => WildcardType
2784
- case tp : TypeParamRef if ! seen.contains(tp) => WildcardType
2785
- case _ => mapOver(tp)
2786
- }
2787
- }.apply(tp)
2788
2767
2789
2768
val defn .MatchCase (pat, body) = cas1
2790
2769
@@ -2799,8 +2778,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
2799
2778
body
2800
2779
}
2801
2780
}
2802
- else if (isSubType(widenAbstractTypes(scrut), widenAbstractTypes(pat)))
2803
- Some (NoType )
2804
2781
else if (provablyDisjoint(scrut, pat))
2805
2782
// We found a proof that `scrut` and `pat` are incompatible.
2806
2783
// The search continues.
0 commit comments