scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Spurious unused warning in for comprehension #12801

Closed tgodzik closed 1 year ago

tgodzik commented 1 year ago

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 commented 1 year ago

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

SethTisue commented 1 year ago

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

SethTisue commented 1 year ago

@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 commented 1 year ago

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.

SethTisue commented 1 year ago

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 commented 1 year ago

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

som-snytt commented 1 year ago

@tgodzik scalac -nowarn