Skip to content

Commit 11961bb

Browse files
committed
Streamlining
- drop a test which prevented a check in isInstanceOfEvaluator but which can be dropped with the more precise types in TypeTestCasts - move a test which was only partially effective in RefChecks to TypeTestCasts (problem is again testing against &/| types).
1 parent 95d660b commit 11961bb

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,22 @@ trait TypeTestsCasts {
5555
*/
5656
def isCheckable =
5757
foundCls.isClass && testCls.isClass &&
58-
foundCls.isPrimitiveValueClass == testCls.isPrimitiveValueClass &&
59-
// if `found` is primitive but `test` is not, it's illegal anyway
58+
!(testCls.isPrimitiveValueClass && !foundCls.isPrimitiveValueClass) &&
6059
// if `test` is primitive but `found` is not, we might have a case like
6160
// found = java.lang.Integer, test = Int, which could be true
6261
// (not sure why that is so, but scalac behaves the same way)
63-
!isDerivedValueClass(foundCls) && !isDerivedValueClass(testCls) &&
62+
!isDerivedValueClass(foundCls) && !isDerivedValueClass(testCls)
6463
// we don't have the logic to handle derived value classes
65-
foundCls != defn.ObjectClass
66-
// if `foundCls == Object`, it could have been `Any` before erasure.
6764

6865
/** Check whether a runtime test that a value of `foundCls` can be a `testCls`
6966
* can be true in some cases. Issure a warning or an error if that's not the case.
7067
*/
7168
def checkSensical: Boolean =
7269
if (!isCheckable) true
70+
else if (foundCls.isPrimitiveValueClass && !testCls.isPrimitiveValueClass) {
71+
ctx.error("cannot test if value types are references", tree.pos)
72+
false
73+
}
7374
else if (!foundCls.derivesFrom(testCls)) {
7475
if (foundCls.is(Final)) {
7576
unreachable(i"$foundCls is not a subclass of $testCls")

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -872,22 +872,6 @@ class RefChecks extends MiniPhase { thisTransformer =>
872872
currentLevel.enterReference(tree.tpe.typeSymbol, tree.pos)
873873
tree
874874
}
875-
876-
override def transformTypeApply(tree: tpd.TypeApply)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
877-
tree.fun match {
878-
case fun@Select(qual, selector) =>
879-
val sym = tree.symbol
880-
881-
if (sym == defn.Any_isInstanceOf) {
882-
val argType = tree.args.head.tpe
883-
val qualCls = qual.tpe.widen.classSymbol
884-
val argCls = argType.classSymbol
885-
if (qualCls.isPrimitiveValueClass && !argCls.isPrimitiveValueClass) ctx.error("isInstanceOf cannot test if value types are references", tree.pos)
886-
}
887-
case _ =>
888-
}
889-
tree
890-
}
891875
}
892876
}
893877

0 commit comments

Comments
 (0)