Skip to content

Commit d02d4b8

Browse files
committed
Avoid erasure/preErasure issues around Any in transformIsInstanceOf
The testType Any is erased to Object, but the expr type Int isn't erased to Integer, so then it fails as Int !<: Object. We avoid the problem by feeding in AnyVal, leading to a (possibly elided) non-null test only.
1 parent 4293a45 commit d02d4b8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ object TypeTestsCasts {
358358
report.error(em"$untestable cannot be used in runtime type tests", tree.srcPos)
359359
constant(expr, Literal(Constant(false)))
360360
case _ =>
361-
val erasedTestType = erasure(testType)
361+
val erasedTestType =
362+
if testType.isAny && expr.tpe.isPrimitiveValueType then
363+
defn.AnyValType
364+
else
365+
erasure(testType)
362366
transformIsInstanceOf(expr, erasedTestType, erasedTestType, flagUnrelated)
363367
}
364368

tests/pos/i21544.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Test():
2+
def m1(xs: List[Boolean]) = for (x: Any) <- xs yield x

0 commit comments

Comments
 (0)