File tree 3 files changed +23
-1
lines changed
src/dotty/tools/dotc/core
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
2881
2881
true
2882
2882
case (_, _ : HKLambda ) =>
2883
2883
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
2884
2890
case (tp1 : OrType , _) =>
2885
2891
provablyDisjoint(tp1.tp1, tp2) && provablyDisjoint(tp1.tp2, tp2)
2886
2892
case (_, tp2 : OrType ) =>
@@ -2891,6 +2897,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2891
2897
case (_, tp2 : AndType ) =>
2892
2898
! (tp2 <:< tp1)
2893
2899
&& (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
2894
2906
case (tp1 : NamedType , _) if gadtBounds(tp1.symbol) != null =>
2895
2907
provablyDisjoint(gadtBounds(tp1.symbol).uncheckedNN.hi, tp2)
2896
2908
|| provablyDisjoint(tp1.superTypeNormalized, tp2)
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ i15158.scala
57
57
i15155.scala
58
58
i15827.scala
59
59
i18211.scala
60
+ i20897.scala
60
61
61
62
# Opaque type
62
63
i5720.scala
@@ -112,4 +113,3 @@ i15525.scala
112
113
i19955a.scala
113
114
i19955b.scala
114
115
i20053b.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