Skip to content

Commit 4086ada

Browse files
committed
Remove disjointness of invariant type params based on isSameType.
It does not seem to bring anything in practice, and it is easier to specify things without it.
1 parent a84fbb1 commit 4086ada

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,17 +2991,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
29912991
end provablyDisjointClasses
29922992

29932993
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-
30052994
// It is possible to conclude that two types applied are disjoint by
30062995
// looking at covariant type parameters if the said type parameters
30072996
// are disjoint and correspond to fields.
@@ -3010,20 +2999,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
30102999
def covariantDisjoint(tp1: Type, tp2: Type, tparam: TypeParamInfo): Boolean =
30113000
provablyDisjoint(tp1, tp2, pending) && typeparamCorrespondsToField(cls.appliedRef, tparam)
30123001

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.
30223003
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)
30273005

30283006
args1.lazyZip(args2).lazyZip(cls.typeParams).exists {
30293007
(arg1, arg2, tparam) =>

0 commit comments

Comments
 (0)