Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid erasure/preErasure issues around Any in transformIsInstanceOf #21647

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
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


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
Loading