Skip to content

Commit 545930d

Browse files
committed
tune specification
1 parent 9ee4518 commit 545930d

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ object Checkable {
4242
import ProtoTypes._
4343

4444
/** Whether `(x:X).isInstanceOf[P]` can be checked at runtime?
45+
*
46+
* Replace `T @unchecked` and pattern binder types (e.g., `_$1`) in P with WildcardType, then check:
4547
*
4648
* 1. if `P` is a singleton type, TRUE
4749
* 2. if `P` is WildcardType, TRUE
48-
* 3. if `P = T @unchecked`, TRUE
49-
* 4. if `P` refers to an abstract type member or type parameter, FALSE
50-
* 5. if `P = Array[T]`, checkable(E, T) where `E` is the element type of `X`, defaults to `Any`.
51-
* 6. if `P` is `pre.F[Ts]` and `pre.F` refers to a class which is not `Array`:
50+
* 3. if `P` refers to an abstract type member or type parameter, FALSE
51+
* 4. if `P = Array[T]`, checkable(E, T) where `E` is the element type of `X`, defaults to `Any`.
52+
* 5. if `P` is `pre.F[Ts]` and `pre.F` refers to a class which is not `Array`:
5253
* (a) replace `Ts` with fresh type variables `Xs`
5354
* (b) instantiate `Xs` with the constraint `pre.F[Xs] <:< X`
54-
* (c) `pre.F[Xs] <:< P2`, where `P2` is `P` with pattern binder types (e.g., `_$1`)
55-
* replaced with `WildcardType`.
56-
* 7. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
57-
* 8. if `P` is a refinement type, FALSE
58-
* 9. otherwise, TRUE
55+
* (c) `pre.F[Xs] <:< P`
56+
* 6. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
57+
* 7. if `P` is a refinement type, FALSE
58+
* 8. otherwise, TRUE
5959
*/
6060
def checkable(X: Type, P: Type)(implicit ctx: Context): Boolean = {
6161
def Psym = P.dealias.typeSymbol
@@ -73,23 +73,21 @@ object Checkable {
7373
}
7474

7575
def isClassDetermined(tpe: AppliedType)(implicit ctx: Context) = {
76-
val AppliedType(tycon, args) = tpe
76+
val AppliedType(tycon, _) = tpe
7777
val tvars = tycon.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
7878
val P1 = tycon.appliedTo(tvars)
7979

8080
debug.println("P1 : " + P1.show)
8181
debug.println("X : " + X.widen)
8282

8383
!(P1 <:< X.widen) || {
84-
val P2 = replaceBinderMap.apply(P)
85-
val res = isFullyDefined(P1, ForceDegree.noBottom) && P1 <:< P2
86-
debug.println("P2: " + P2.show)
87-
debug.println("P1 <:< P2 = " + res)
84+
val res = isFullyDefined(P1, ForceDegree.noBottom) && P1 <:< tpe
85+
debug.println("P1 <:< P = " + res)
8886
res
8987
}
9088
}
9189

92-
val res = P match {
90+
val res = replaceBinderMap.apply(P) match {
9391
case _: SingletonType => true
9492
case WildcardType => true
9593
case defn.ArrayOf(tpT) =>
@@ -100,9 +98,9 @@ object Checkable {
10098
case tpe: AppliedType => !isAbstract && isClassDetermined(tpe)
10199
case AndType(tp1, tp2) => checkable(X, tp1) && checkable(X, tp2)
102100
case OrType(tp1, tp2) => checkable(X, tp1) && checkable(X, tp2)
103-
case AnnotatedType(t, an) => an.symbol == defn.UncheckedAnnot || checkable(X, t)
101+
case AnnotatedType(t, an) => checkable(X, t)
104102
case _: RefinedType => false
105-
case _ => replaceBinderMap.apply(P) == WildcardType || !isAbstract
103+
case _ => !isAbstract
106104
}
107105

108106
debug.println(i"checking ${X.show} isInstanceOf ${P} = $res")

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class CompilationTests extends ParallelTesting {
190190
compileFile("tests/neg-custom-args/noimports2.scala", defaultOptions.and("-Yno-imports")) +
191191
compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes) +
192192
compileFile("tests/neg-custom-args/i1754.scala", allowDeepSubtypes) +
193-
compileFilesInDir("tests/neg-custom-args/isInstanceOf", defaultOptions and "-Xfatal-warnings") +
193+
compileFilesInDir("tests/neg-custom-args/isInstanceOf", allowDeepSubtypes and "-Xfatal-warnings") +
194194
compileFile("tests/neg-custom-args/i3627.scala", allowDeepSubtypes)
195195
}.checkExpectedErrors()
196196

0 commit comments

Comments
 (0)