Skip to content

Commit 01288d2

Browse files
authored
Avoid erasure/preErasure issues around Any in transformIsInstanceOf (#21647)
2 parents 3e9b248 + 49d876a commit 01288d2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

+2-1
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 {

tests/pos/i21544.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Test():
2+
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
5+
6+
def v1(xs: List[AnyVal]) = for (x: Any) <- xs yield x
7+
def v2(xs: List[AnyVal]) = for (x: AnyVal) <- xs yield x
8+
def v3(xs: List[AnyVal]) = for (x: Matchable) <- xs yield x
9+
10+
def t1(xs: List[Matchable]) = for (x: Any) <- xs yield x
11+
def t2(xs: List[Matchable]) = for (x: Matchable) <- xs yield x
12+
13+
def a1(xs: List[Any]) = for (x: Any) <- xs yield x

0 commit comments

Comments
 (0)