Skip to content

Commit

Permalink
Avoid erasure/preErasure issues around Any in transformIsInstanceOf
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dwijnand committed Sep 25, 2024
1 parent 4293a45 commit d02d4b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ object TypeTestsCasts {
report.error(em"$untestable cannot be used in runtime type tests", tree.srcPos)
constant(expr, Literal(Constant(false)))
case _ =>
val erasedTestType = erasure(testType)
val erasedTestType =
if testType.isAny && expr.tpe.isPrimitiveValueType then
defn.AnyValType
else
erasure(testType)
transformIsInstanceOf(expr, erasedTestType, erasedTestType, flagUnrelated)
}

Expand Down
2 changes: 2 additions & 0 deletions tests/pos/i21544.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Test():
def m1(xs: List[Boolean]) = for (x: Any) <- xs yield x

0 comments on commit d02d4b8

Please sign in to comment.