Skip to content

Commit

Permalink
Avoid erasure/preErasure issues around Any in transformIsInstanceOf (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand authored Nov 2, 2024
2 parents 3e9b248 + 49d876a commit 01288d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ object TypeTestsCasts {
else foundClasses.exists(check)
end checkSensical

if (expr.tpe <:< testType) && inMatch then
val tp = if expr.tpe.isPrimitiveValueType then defn.boxedType(expr.tpe) else expr.tpe
if tp <:< testType && inMatch then
if expr.tpe.isNotNull then constant(expr, Literal(Constant(true)))
else expr.testNotNull
else {
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i21544.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Test():
def m1(xs: List[Boolean]) = for (x: Any) <- xs yield x
def m2(xs: List[Boolean]) = for (x: AnyVal) <- xs yield x
def m3(xs: List[Boolean]) = for (x: Matchable) <- xs yield x

def v1(xs: List[AnyVal]) = for (x: Any) <- xs yield x
def v2(xs: List[AnyVal]) = for (x: AnyVal) <- xs yield x
def v3(xs: List[AnyVal]) = for (x: Matchable) <- xs yield x

def t1(xs: List[Matchable]) = for (x: Any) <- xs yield x
def t2(xs: List[Matchable]) = for (x: Matchable) <- xs yield x

def a1(xs: List[Any]) = for (x: Any) <- xs yield x

0 comments on commit 01288d2

Please sign in to comment.