Skip to content

-Wunused gives false positives for generator value with a guard #16925

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

Closed
rochala opened this issue Feb 15, 2023 · 1 comment · Fixed by #17020
Closed

-Wunused gives false positives for generator value with a guard #16925

rochala opened this issue Feb 15, 2023 · 1 comment · Fixed by #17020
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@rochala
Copy link
Contributor

rochala commented Feb 15, 2023

Compiler version

3.3.1-RC1-bin-20230213-8c616bf-NIGHTLY

Minimized code

//> using scala "3.3.1-RC1-bin-20230213-8c616bf-NIGHTLY"
//> using options "-Wunused:all"

@main
def hello =
  for {
    i <- 1 to 2 if true
    _ = println(i)
  } yield ()

Output

Compiling project (Scala 3.3.1-RC1-bin-20230213-8c616bf-NIGHTLY, JVM)
[warn] ./src/scala3/FileA.scala:8:5: unused local definition
[warn]     i <- 1 to 2 if true
[warn]     ^

Expectation

Don't report i as unused local definition

@KacperFKorban
Copy link
Member

KacperFKorban commented Feb 15, 2023

This is due to the fact that a for like

for {
  i <- 1.to(2)
  if true
} yield i

will be desugared to

1.to(2).withFilter { i =>
  true
}.map { i =>
  i
}

So i in the withFilter call is unused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants