Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that going to trigger with the same issue with any other type that erases to Object? Like ... AnyVal itself?

There's supposed to already be logic in transformIsInstanceOf to avoid a type test when expr.tpe <:< testType:

if (expr.tpe <:< testType) && inMatch then
if expr.tpe.isNotNull then constant(expr, Literal(Constant(true)))
else expr.testNotNull

The problem is that it tests on erased types, instead of the original types. Addressing that at the root should be more robust, shouldn't it?

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
Loading