Skip to content

Commit b204c7d

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 6904fb0 commit b204c7d

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
@@ -2547,17 +2547,17 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
25472547
def covariantDisjoint(tp1: Type, tp2: Type, tparam: TypeParamInfo): Boolean =
25482548
provablyDisjoint(tp1, tp2) && typeparamCorrespondsToField(tycon1, tparam)
25492549

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

0 commit comments

Comments
 (0)