Skip to content

Commit 0b9f8a8

Browse files
committed
fix check for Array
1 parent 94d8313 commit 0b9f8a8

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Printers {
3131
val plugins: Printer = noPrinter
3232
val simplify: Printer = noPrinter
3333
val subtyping: Printer = noPrinter
34-
val transforms: Printer = new Printer
34+
val transforms: Printer = noPrinter
3535
val typr: Printer = noPrinter
3636
val unapp: Printer = noPrinter
3737
val variances: Printer = noPrinter

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class IsInstanceOfChecker extends MiniPhase {
2020
def ensureCheckable(qual: Tree, pt: Tree): Tree = {
2121
if (!Checkable.checkable(qual.tpe, pt.tpe))
2222
ctx.warning(
23-
s"the type test for ${pt} cannot be checked at runtime",
23+
s"the type test for ${pt.show} cannot be checked at runtime",
2424
tree.pos
2525
)
2626

@@ -43,16 +43,18 @@ object Checkable {
4343

4444
/** Whether `(x:X).isInstanceOf[P]` can be checked at runtime?
4545
*
46-
* 0. if `P` is a singleton type, TRUE
47-
* 1. if `P` refers to an abstract type member, FALSE
48-
* 2. if `P = Array[T]`, checkable(E, T) where `E` is the element type of `X`, defaults to `Any`.
49-
* 3. if `P` is `pre.F[Ts]` and `pre.F` refers to a class which is not `Array`:
46+
* 1. if `P` is a singleton type, TRUE
47+
* 2. if `P` is WildcardType, TRUE
48+
* 3. if `P` refers to an abstract type member, FALSE
49+
* 4. if `P = Array[T]`, checkable(E, T) where `E` is the element type of `X`, defaults to `Any`.
50+
* 5. if `P` is `pre.F[Ts]` and `pre.F` refers to a class which is not `Array`:
5051
* (a) replace `Ts` with fresh type variables `Xs`
5152
* (b) instantiate `Xs` with the constraint `pre.F[Xs] <:< X`
5253
* (c) `pre.F[Xs] <:< P2`, where `P2` is `P` with pattern binder types (e.g., `_$1`)
5354
* replaced with `WildcardType`.
54-
* 4. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
55-
* 5. otherwise, TRUE
55+
* 6. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
56+
* 7. if `P` is a refinement type, FALSE
57+
* 8. otherwise, TRUE
5658
*/
5759
def checkable(X: Type, P: Type)(implicit ctx: Context): Boolean = {
5860
def Psym = P.dealias.typeSymbol
@@ -86,8 +88,9 @@ object Checkable {
8688
}
8789
}
8890

89-
P match {
91+
val res = P match {
9092
case _: SingletonType => true
93+
case WildcardType => true
9194
case defn.ArrayOf(tpT) =>
9295
X match {
9396
case defn.ArrayOf(tpE) => checkable(tpE, tpT)
@@ -96,7 +99,12 @@ object Checkable {
9699
case tpe: AppliedType => !isAbstract && isClassDetermined(tpe)(ctx.fresh.setFreshGADTBounds)
97100
case AndType(tp1, tp2) => checkable(X, tp1) && checkable(X, tp2)
98101
case OrType(tp1, tp2) => checkable(X, tp1) && checkable(X, tp2)
99-
case _ => !isAbstract
102+
case AnnotatedType(tp, _) => checkable(X, tp)
103+
case _ => replaceBinderMap.apply(P) == WildcardType || !isAbstract
100104
}
105+
106+
debug.println(i"checking ${X.show} isInstanceOf ${P} = $res")
107+
108+
res
101109
}
102110
}

0 commit comments

Comments
 (0)