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

false positive unused warning in for comprehensions #13095

Open
xuwei-k opened this issue Mar 10, 2025 · 3 comments · May be fixed by scala/scala#11012
Open

false positive unused warning in for comprehensions #13095

xuwei-k opened this issue Mar 10, 2025 · 3 comments · May be fixed by scala/scala#11012
Assignees
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) has PR
Milestone

Comments

@xuwei-k
Copy link

xuwei-k commented Mar 10, 2025

Reproduction steps

Scala 2.13.15, 2.13.16 and 2.13.17-bin-ebdaf73

build.sbt

Global / resolvers += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/"

scalaVersion := "2.13.17-bin-ebdaf73"

scalacOptions += "-Wunused"

Main.scala

case class A(x: Int, y: Int)

object Main {
  for {
    a <- List.empty[A]
    A(x, y) = a
  } yield x + y
}

Problem

[warn] false-positive-unused-warn/Main.scala:6:7: pattern var x in value $anonfun is never used
[warn]     A(x, y) = a
[warn]       ^
[warn] false-positive-unused-warn/Main.scala:6:10: pattern var y in value $anonfun is never used
[warn]     A(x, y) = a
[warn]          ^
[warn] two warnings found

x and y not unused.

@SethTisue
Copy link
Member

looks like one @som-snytt will be all over

@som-snytt
Copy link

Yes, thanks, although I believe the current idiom is "all under".

Thanks for the report!

@som-snytt som-snytt added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Mar 10, 2025
@SethTisue SethTisue added this to the 2.13.17 milestone Mar 10, 2025
@som-snytt
Copy link

Ha, this is because it sees that pattern vars in A(x, y) have the "canonical names" in the case class, so it doesn't want to warn about them. However, that means they aren't tracked, so that the artifact valdefs appear unused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants