Skip to content

Commit fbfba7c

Browse files
OlivierBlanvillainanatoliykmetyuk
authored andcommitted
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 e6b8604 commit fbfba7c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -2585,17 +2585,17 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
25852585
def covariantDisjoint(tp1: Type, tp2: Type, tparam: TypeParamInfo): Boolean =
25862586
provablyDisjoint(tp1, tp2) && typeparamCorrespondsToField(tycon1, tparam)
25872587

2588-
// In the invariant case, we used a weaker version of disjointness:
2589-
// we consider types not equal with respect to =:= to be disjoint
2588+
// In the invariant case, we also use a stronger notion of disjointness:
2589+
// we consider fully instantiated types not equal wrt =:= to be disjoint
25902590
// (under any context). This is fine because it matches the runtime
25912591
// semantics of pattern matching. To implement a pattern such as
25922592
// `case Inv[T] => ...`, one needs a type tag for `T` and the compiler
25932593
// is used at runtime to check it the scrutinee's type is =:= to `T`.
2594-
// Note that this is currently a theoretical concern since we Dotty
2594+
// Note that this is currently a theoretical concern since Dotty
25952595
// doesn't have type tags, meaning that users cannot write patterns
25962596
// that do type tests on higher kinded types.
25972597
def invariantDisjoint(tp1: Type, tp2: Type, tparam: TypeParamInfo): Boolean =
2598-
covariantDisjoint(tp1, tp2, tparam) ||
2598+
provablyDisjoint(tp1, tp2) ||
25992599
!isSameType(tp1, tp2) &&
26002600
fullyInstantiated(tp1) && // We can only trust a "no" from `isSameType` when
26012601
fullyInstantiated(tp2) // both `tp1` and `tp2` are fully instantiated.

0 commit comments

Comments
 (0)