Skip to content

Commit 6935251

Browse files
dwijnandtgodzik
authored andcommitted
Simplify transformIsInstanceOf check
[Cherry-picked 7b721f0]
1 parent b611bca commit 6935251

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ object TypeTestsCasts {
250250
else foundClasses.exists(check)
251251
end checkSensical
252252

253-
if (expr.tpe <:< testType) && inMatch then
253+
val tp = if expr.tpe.isPrimitiveValueType then defn.boxedType(expr.tpe) else expr.tpe
254+
if tp <:< testType && inMatch then
254255
if expr.tpe.isNotNull then constant(expr, Literal(Constant(true)))
255256
else expr.testNotNull
256257
else {
@@ -352,11 +353,7 @@ object TypeTestsCasts {
352353
report.error(em"$untestable cannot be used in runtime type tests", tree.srcPos)
353354
constant(expr, Literal(Constant(false)))
354355
case _ =>
355-
val erasedTestType =
356-
if testType.isAny && expr.tpe.isPrimitiveValueType then
357-
defn.AnyValType
358-
else
359-
erasure(testType)
356+
val erasedTestType = erasure(testType)
360357
transformIsInstanceOf(expr, erasedTestType, erasedTestType, flagUnrelated)
361358
}
362359

tests/pos/i21544.scala

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

0 commit comments

Comments
 (0)