@@ -2388,7 +2388,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
23882388 case _ => false
23892389 }
23902390
2391-
23922391 /** Are `tp1` and `tp2` provablyDisjoint types?
23932392 *
23942393 * `true` implies that we found a proof; uncertainty defaults to `false`.
@@ -2507,17 +2506,25 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
25072506 case (_, tp2 : AndType ) =>
25082507 ! (tp2 <:< tp1)
25092508 && (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)
25102513 case (tp1 : TypeProxy , tp2 : TypeProxy ) =>
2511- provablyDisjoint(tp1.underlying , tp2) || provablyDisjoint(tp1, tp2.underlying )
2514+ provablyDisjoint(matchTypeSuperType( tp1) , tp2) || provablyDisjoint(tp1, matchTypeSuperType( tp2) )
25122515 case (tp1 : TypeProxy , _) =>
2513- provablyDisjoint(tp1.underlying , tp2)
2516+ provablyDisjoint(matchTypeSuperType( tp1) , tp2)
25142517 case (_, tp2 : TypeProxy ) =>
2515- provablyDisjoint(tp1, tp2.underlying )
2518+ provablyDisjoint(tp1, matchTypeSuperType( tp2) )
25162519 case _ =>
25172520 false
25182521 }
25192522 }
25202523
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+
25212528 protected def explainingTypeComparer = ExplainingTypeComparer (comparerContext)
25222529 protected def trackingTypeComparer = TrackingTypeComparer (comparerContext)
25232530
@@ -2757,34 +2764,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
27572764 case _ =>
27582765 cas
27592766 }
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)
27882767
27892768 val defn .MatchCase (pat, body) = cas1
27902769
@@ -2799,8 +2778,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
27992778 body
28002779 }
28012780 }
2802- else if (isSubType(widenAbstractTypes(scrut), widenAbstractTypes(pat)))
2803- Some (NoType )
28042781 else if (provablyDisjoint(scrut, pat))
28052782 // We found a proof that `scrut` and `pat` are incompatible.
28062783 // The search continues.
0 commit comments