diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 8223c60aab5f..5a7fb258f4eb 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -250,7 +250,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 { diff --git a/tests/pos/i21544.scala b/tests/pos/i21544.scala new file mode 100644 index 000000000000..b2d978ea7d02 --- /dev/null +++ b/tests/pos/i21544.scala @@ -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