@@ -2404,14 +2404,20 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
24042404 * 1. Single inheritance of classes
24052405 * 2. Final classes cannot be extended
24062406 * 3. ConstantTypes with distinct values are non intersecting
2407- * 4. There is no value of type Nothing
2407+ * 4. TermRefs with distinct values are non intersecting
2408+ * 5. There is no value of type Nothing
24082409 *
24092410 * Note on soundness: the correctness of match types relies on on the
24102411 * property that in all possible contexts, the same match type expression
24112412 * is either stuck or reduces to the same case.
24122413 */
24132414 def provablyDisjoint (tp1 : Type , tp2 : Type )(using Context ): Boolean = {
24142415 // println(s"provablyDisjoint(${tp1.show}, ${tp2.show})")
2416+
2417+ def isEnumValueOrModule (ref : TermRef ): Boolean =
2418+ val sym = ref.termSymbol
2419+ sym.isAllOf(EnumCase , butNot= JavaDefined ) || sym.is(Module )
2420+
24152421 /** Can we enumerate all instantiations of this type? */
24162422 def isClosedSum (tp : Symbol ): Boolean =
24172423 tp.is(Sealed ) && tp.isOneOf(AbstractOrTrait ) && ! tp.hasAnonymousChild
@@ -2517,6 +2523,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
25172523 provablyDisjoint(gadtBounds(tp1.symbol).hi, tp2) || provablyDisjoint(tp1.superType, tp2)
25182524 case (_, tp2 : NamedType ) if gadtBounds(tp2.symbol) != null =>
25192525 provablyDisjoint(tp1, gadtBounds(tp2.symbol).hi) || provablyDisjoint(tp1, tp2.superType)
2526+ case (tp1 : TermRef , tp2 : TermRef ) if isEnumValueOrModule(tp1) && isEnumValueOrModule(tp2) =>
2527+ tp1.termSymbol != tp2.termSymbol
25202528 case (tp1 : TypeProxy , tp2 : TypeProxy ) =>
25212529 provablyDisjoint(matchTypeSuperType(tp1), tp2) || provablyDisjoint(tp1, matchTypeSuperType(tp2))
25222530 case (tp1 : TypeProxy , _) =>
0 commit comments