Skip to content

Commit 7b721f0

Browse files
committed
Simplify transformIsInstanceOf check
1 parent d02d4b8 commit 7b721f0

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
@@ -256,7 +256,8 @@ object TypeTestsCasts {
256256
else foundClasses.exists(check)
257257
end checkSensical
258258

259-
if (expr.tpe <:< testType) && inMatch then
259+
val tp = if expr.tpe.isPrimitiveValueType then defn.boxedType(expr.tpe) else expr.tpe
260+
if tp <:< testType && inMatch then
260261
if expr.tpe.isNotNull then constant(expr, Literal(Constant(true)))
261262
else expr.testNotNull
262263
else {
@@ -358,11 +359,7 @@ object TypeTestsCasts {
358359
report.error(em"$untestable cannot be used in runtime type tests", tree.srcPos)
359360
constant(expr, Literal(Constant(false)))
360361
case _ =>
361-
val erasedTestType =
362-
if testType.isAny && expr.tpe.isPrimitiveValueType then
363-
defn.AnyValType
364-
else
365-
erasure(testType)
362+
val erasedTestType = erasure(testType)
366363
transformIsInstanceOf(expr, erasedTestType, erasedTestType, flagUnrelated)
367364
}
368365

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)