Skip to content

Commit a79aa0c

Browse files
Backport "Fix #20897: Make Nothing ⋔ Nothing, as per spec." to LTS (#22077)
Backports #21241 to the 3.3.5. PR submitted by the release tooling. [skip ci]
2 parents 341f26c + 55861e9 commit a79aa0c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+12
Original file line numberDiff line numberDiff 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)

Diff for: compiler/test/dotc/pos-test-pickling.blacklist

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ i15158.scala
5757
i15155.scala
5858
i15827.scala
5959
i18211.scala
60+
i20897.scala
6061

6162
# Opaque type
6263
i5720.scala
@@ -112,4 +113,3 @@ i15525.scala
112113
i19955a.scala
113114
i19955b.scala
114115
i20053b.scala
115-

Diff for: tests/pos/i20897.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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

0 commit comments

Comments
 (0)