File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
src/dotty/tools/dotc/core Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -2881,6 +2881,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
28812881 true
28822882 case (_, _ : HKLambda ) =>
28832883 true
2884+ /* Nothing is not a class type in the spec but dotc represents it as if it were one.
2885+ * Get it out of the way early to avoid mistakes (see for example #20897).
2886+ * Nothing ⋔ T and T ⋔ Nothing for all T.
2887+ */
2888+ case (tp1, tp2) if tp1.isExactlyNothing || tp2.isExactlyNothing =>
2889+ true
28842890 case (tp1 : OrType , _) =>
28852891 provablyDisjoint(tp1.tp1, tp2) && provablyDisjoint(tp1.tp2, tp2)
28862892 case (_, tp2 : OrType ) =>
@@ -2891,6 +2897,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
28912897 case (_, tp2 : AndType ) =>
28922898 ! (tp2 <:< tp1)
28932899 && (provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1))
2900+ /* Handle AnyKind now for the same reason as Nothing above: it is not a real class type.
2901+ * Other than the rules with Nothing, unions and intersections, there is structurally
2902+ * no rule such that AnyKind ⋔ T or T ⋔ AnyKind for any T.
2903+ */
2904+ case (tp1, tp2) if tp1.isDirectRef(AnyKindClass ) || tp2.isDirectRef(AnyKindClass ) =>
2905+ false
28942906 case (tp1 : NamedType , _) if gadtBounds(tp1.symbol) != null =>
28952907 provablyDisjoint(gadtBounds(tp1.symbol).uncheckedNN.hi, tp2)
28962908 || provablyDisjoint(tp1.superTypeNormalized, tp2)
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ i15158.scala
5757i15155.scala
5858i15827.scala
5959i18211.scala
60+ i20897.scala
6061
6162# Opaque type
6263i5720.scala
@@ -112,4 +113,3 @@ i15525.scala
112113i19955a.scala
113114i19955b.scala
114115i20053b.scala
115-
Original file line number Diff line number Diff line change 1+ object Test :
2+ type Disj [A , B ] =
3+ A match
4+ case B => true
5+ case _ => false
6+
7+ def f (a : Disj [1 | Nothing , 2 | Nothing ]): Unit = ()
8+
9+ val t = f(false )
10+ end Test
You can’t perform that action at this time.
0 commit comments