@@ -2991,17 +2991,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2991
2991
end provablyDisjointClasses
2992
2992
2993
2993
private def provablyDisjointTypeArgs (cls : ClassSymbol , args1 : List [Type ], args2 : List [Type ], pending : util.HashSet [(Type , Type )])(using Context ): Boolean =
2994
- def fullyInstantiated (tp : Type ): Boolean = new TypeAccumulator [Boolean ] {
2995
- override def apply (x : Boolean , t : Type ) =
2996
- x && {
2997
- t.dealias match {
2998
- case tp : TypeRef if ! tp.symbol.isClass => false
2999
- case _ : SkolemType | _ : TypeVar | _ : TypeParamRef | _ : TypeBounds => false
3000
- case _ => foldOver(x, t)
3001
- }
3002
- }
3003
- }.apply(true , tp)
3004
-
3005
2994
// It is possible to conclude that two types applied are disjoint by
3006
2995
// looking at covariant type parameters if the said type parameters
3007
2996
// are disjoint and correspond to fields.
@@ -3010,20 +2999,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
3010
2999
def covariantDisjoint (tp1 : Type , tp2 : Type , tparam : TypeParamInfo ): Boolean =
3011
3000
provablyDisjoint(tp1, tp2, pending) && typeparamCorrespondsToField(cls.appliedRef, tparam)
3012
3001
3013
- // In the invariant case, we also use a stronger notion of disjointness:
3014
- // we consider fully instantiated types not equal wrt =:= to be disjoint
3015
- // (under any context). This is fine because it matches the runtime
3016
- // semantics of pattern matching. To implement a pattern such as
3017
- // `case Inv[T] => ...`, one needs a type tag for `T` and the compiler
3018
- // is used at runtime to check it the scrutinee's type is =:= to `T`.
3019
- // Note that this is currently a theoretical concern since Dotty
3020
- // doesn't have type tags, meaning that users cannot write patterns
3021
- // that do type tests on higher kinded types.
3002
+ // In the invariant case, direct type parameter disjointness is enough.
3022
3003
def invariantDisjoint (tp1 : Type , tp2 : Type , tparam : TypeParamInfo ): Boolean =
3023
- provablyDisjoint(tp1, tp2, pending) ||
3024
- ! isSameType(tp1, tp2) &&
3025
- fullyInstantiated(tp1) && // We can only trust a "no" from `isSameType` when
3026
- fullyInstantiated(tp2) // both `tp1` and `tp2` are fully instantiated.
3004
+ provablyDisjoint(tp1, tp2, pending)
3027
3005
3028
3006
args1.lazyZip(args2).lazyZip(cls.typeParams).exists {
3029
3007
(arg1, arg2, tparam) =>
0 commit comments