Skip to content

Commit b6336cd

Browse files
authored
Merge pull request #73 from scala/backport-lts-3.3-21647
Backport "Avoid erasure/preErasure issues around Any in transformIsInstanceOf" to 3.3 LTS
2 parents 2cbcd26 + aea7d9e commit b6336cd

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
@@ -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 {

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)