Skip to content

Spurious unused warning in for comprehension #12801

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
tgodzik opened this issue Jun 7, 2023 · 7 comments
Closed

Spurious unused warning in for comprehension #12801

tgodzik opened this issue Jun 7, 2023 · 7 comments

Comments

@tgodzik
Copy link

tgodzik commented Jun 7, 2023

Reproduction steps

2.13.11

//> using scala "2.13.11"
//> using options "-Wunused"

class Main {
  def search2(): Iterator[Int] = {
    for {
      pkg <- Array(1).iterator
      if pkg > 1
    } yield 0
  }
}

Problem

pkg is reported as unused

@SethTisue SethTisue changed the title Spurious unusued warnings Spurious unused warnings (2.13.11 regression) Jun 7, 2023
@SethTisue SethTisue added this to the 2.13.12 milestone Jun 7, 2023
@SethTisue
Copy link
Member

SethTisue commented Jun 7, 2023

@som-snytt wdyt, is this a new bug? another dilemma like #10287?

@SethTisue
Copy link
Member

It desugars to foo.withFilter(pkg => ...).map(pkg => ...) and the first pkg is used but the second pkg is not, hence the warning.

@SethTisue SethTisue changed the title Spurious unused warnings (2.13.11 regression) Spurious unused warning in for comprehension (2.13.11 regression) Jun 7, 2023
@SethTisue
Copy link
Member

@tgodzik wait, 2.13.10 is the same

~/tmp/si-12801 % scala-cli compile .                                                           main
Compiling project (Scala 2.13.10, JVM)
[warn] ./S.scala:7:7
[warn] parameter value pkg in anonymous function is never used
[warn]       pkg <- Array(1).iterator
[warn]       ^^^

@som-snytt
Copy link

som-snytt commented Jun 7, 2023

jinx.

Edit: note param warnings are not enabled under -Xlint, which offers only the most robust warnings.

Closing as duplicate. I did hope to tackle the linked issue at some point, for dotty parity.

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2023
@SethTisue SethTisue removed this from the 2.13.12 milestone Jun 7, 2023
@SethTisue SethTisue changed the title Spurious unused warning in for comprehension (2.13.11 regression) Spurious unused warning in for comprehension Jun 7, 2023
@SethTisue
Copy link
Member

Tomasz will make a fresh attempt to determine why he started seeing warnings after a 2.13.11 upgrade that weren't there before.

@tgodzik
Copy link
Author

tgodzik commented Jun 7, 2023

I have no idea why it started showing on 2.13.11 :/ I will add nowarn everywhere now :sigh:

@som-snytt
Copy link

@tgodzik scalac -nowarn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants