Skip to content

Commit 3991198

Browse files
committed
Fix type test warning involving applied types
Previously, the check relied used `maximizeType`, which means that depending on which bound got picked by type inference, the check might fail. Instead, we only need to check if there is a possible constraint solution by making sure both subtype tests return true. I'm not sure if this is always a safe type test, but it at least avoids spurious warnings. This is necessary to bootstrap dotty after the previous commit which added a `dealias` to `recur`, this probably means that there are other situations where `recur` is missing checks.
1 parent aeeb14b commit 3991198

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ object TypeTestsCasts {
4747
* 4. if `P = Array[T]`, checkable(E, T) where `E` is the element type of `X`, defaults to `Any`.
4848
* 5. if `P` is `pre.F[Ts]` and `pre.F` refers to a class which is not `Array`:
4949
* (a) replace `Ts` with fresh type variables `Xs`
50-
* (b) constrain `Xs` with `pre.F[Xs] <:< X`
51-
* (c) instantiate Xs and check `pre.F[Xs] <:< P`
50+
* (b) check that we can constrain `Xs` such that `pre.F[Xs] <:< X` and `pre.F[Xs] <:< P`
51+
* can both be true at the same time.
5252
* 6. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
5353
* 7. if `P` is a refinement type, FALSE
5454
* 8. otherwise, TRUE
@@ -105,12 +105,7 @@ object TypeTestsCasts {
105105
debug.println("P1 : " + P1.show)
106106
debug.println("X : " + X.show)
107107

108-
P1 <:< X // constraint P1
109-
110-
// use fromScala2x to avoid generating pattern bound symbols
111-
maximizeType(P1, span, fromScala2x = true)
112-
113-
val res = P1 <:< P
108+
val res = (P1 <:< X) && (P1 <:< P)
114109
debug.println("P1 : " + P1.show)
115110
debug.println("P1 <:< P = " + res)
116111

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class A[-T]
2+
class B[T] extends A[T]
3+
4+
object Test {
5+
def foo(x: A[Null]) = x match {
6+
case x: B[Null] =>
7+
case _ =>
8+
}
9+
}

0 commit comments

Comments
 (0)