Skip to content

Commit c2ef9b7

Browse files
Update invariantDisjoint check
The previous check was too conservative, is we have a proof that A and B are disjoint, then A and B in Inv[A] and Inv[B] are clearly different types, and Inv[A] and Inv[B] are disjoint. Also the isSameType() && fullyInstantiated check is quite primitive, it can still be useful in some cases.
1 parent a279405 commit c2ef9b7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,17 +2552,17 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
25522552
def covariantDisjoint(tp1: Type, tp2: Type, tparam: TypeParamInfo): Boolean =
25532553
provablyDisjoint(tp1, tp2) && typeparamCorrespondsToField(tycon1, tparam)
25542554

2555-
// In the invariant case, we used a weaker version of disjointness:
2556-
// we consider types not equal with respect to =:= to be disjoint
2555+
// In the invariant case, we also use a stronger notion of disjointness:
2556+
// we consider fully instantiated types not equal wrt =:= to be disjoint
25572557
// (under any context). This is fine because it matches the runtime
25582558
// semantics of pattern matching. To implement a pattern such as
25592559
// `case Inv[T] => ...`, one needs a type tag for `T` and the compiler
25602560
// is used at runtime to check it the scrutinee's type is =:= to `T`.
2561-
// Note that this is currently a theoretical concern since we Dotty
2561+
// Note that this is currently a theoretical concern since Dotty
25622562
// doesn't have type tags, meaning that users cannot write patterns
25632563
// that do type tests on higher kinded types.
25642564
def invariantDisjoint(tp1: Type, tp2: Type, tparam: TypeParamInfo): Boolean =
2565-
covariantDisjoint(tp1, tp2, tparam) || !isSameType(tp1, tp2) && {
2565+
provablyDisjoint(tp1, tp2) || !isSameType(tp1, tp2) && {
25662566
// We can only trust a "no" from `isSameType` when both
25672567
// `tp1` and `tp2` are fully instantiated.
25682568
def fullyInstantiated(tp: Type): Boolean = new TypeAccumulator[Boolean] {

0 commit comments

Comments
 (0)