Skip to content

Commit d61eb85

Browse files
committed
Handle GADT bounds in isInstanceOf type test
1 parent 7e30d84 commit d61eb85

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ object TypeTestsCasts {
105105
debug.println("P1 : " + P1.show)
106106
debug.println("X : " + X.show)
107107

108-
val res = (P1 <:< X) && (P1 <:< P)
108+
P1 <:< X
109+
110+
maximizeType(P1, span, fromScala2x = false)
111+
112+
val res = P1 <:< P
109113
debug.println("P1 : " + P1.show)
110114
debug.println("P1 <:< P = " + res)
111115

@@ -133,8 +137,8 @@ object TypeTestsCasts {
133137
case _ =>
134138
// first try withou striping type parameters for performance
135139
X.classSymbol.exists && P.classSymbol.exists && !X.classSymbol.asClass.mayHaveCommonChild(P.classSymbol.asClass) ||
136-
isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState()) ||
137-
isClassDetermined(stripTypeParam(X), tpe)(ctx.fresh.setNewTyperState())
140+
isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState().setFreshGADTBounds) ||
141+
isClassDetermined(stripTypeParam(X), tpe)(ctx.fresh.setNewTyperState().setFreshGADTBounds)
138142
}
139143
case AndType(tp1, tp2) => recur(X, tp1) && recur(X, tp2)
140144
case OrType(tp1, tp2) => recur(X, tp1) && recur(X, tp2)

tests/neg-custom-args/isInstanceOf/3324g.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Test {
1212
}
1313

1414
def quux[T](a: A[T]): Unit = a match {
15-
case _: B[T] => // should be an error!!
15+
case _: B[T] => // error!!
1616
}
1717

1818
quux(new C[Int])
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class A
2+
class B
3+
4+
type AorB = A | B
5+
6+
def foo(any: Any) = any match {
7+
case aorb: AorB =>
8+
case _ =>
9+
}
10+
11+
def bar[T](x: List[T]) = x.isInstanceof[List[Int]] // error
12+

tests/neg-custom-args/isInstanceOf/patmat-applied.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ object Test {
77
case _ =>
88
}
99
}
10+
11+
def bar[T](x: List[T]) = x.isInstanceof[List[Int]] // error

0 commit comments

Comments
 (0)