Skip to content

Commit 1005e69

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 1005e69

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ trait TypeTestsCasts {
6060
// if `test` is primitive but `found` is not, we might have a case like
6161
// found = java.lang.Integer, test = Int, which could be true
6262
// (not sure why that is so, but scalac behaves the same way)
63-
!isDerivedValueClass(foundCls) && !isDerivedValueClass(testCls) &&
63+
!isDerivedValueClass(foundCls) && !isDerivedValueClass(testCls)
6464
// 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.
6765

6866
/** Check whether a runtime test that a value of `foundCls` can be a `testCls`
6967
* can be true in some cases. Issure a warning or an error if that's not the case.
@@ -81,6 +79,10 @@ trait TypeTestsCasts {
8179
unreachable(i"$foundCls and $testCls are unrelated")
8280
false
8381
}
82+
else if (foundCls.isPrimitiveValueClass && !testCls.isPrimitiveValueClass) {
83+
ctx.error("cannot test if value types are references", tree.pos)
84+
false
85+
}
8486
else true
8587
}
8688
else true

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)