Skip to content

Commit b611bca

Browse files
dwijnandtgodzik
authored andcommitted
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. [Cherry-picked d02d4b8]
1 parent 4895a18 commit b611bca

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
@@ -352,7 +352,11 @@ object TypeTestsCasts {
352352
report.error(em"$untestable cannot be used in runtime type tests", tree.srcPos)
353353
constant(expr, Literal(Constant(false)))
354354
case _ =>
355-
val erasedTestType = erasure(testType)
355+
val erasedTestType =
356+
if testType.isAny && expr.tpe.isPrimitiveValueType then
357+
defn.AnyValType
358+
else
359+
erasure(testType)
356360
transformIsInstanceOf(expr, erasedTestType, erasedTestType, flagUnrelated)
357361
}
358362

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)