Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions tests/pos/i21544.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more suggestions for tests:

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

Loading