scala / bug

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

Unused warning for used variable in for comprehension filter #12912

Closed esgott closed 7 months ago

esgott commented 7 months ago

Reproduction steps

Scala version: 2.13.12

build.sbt:

scalaVersion := "2.13.12"

addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")

scalacOptions ++= Seq(
  "-Wunused"
)

src.scala:

object src {
  val foo = for {
    a <- Some("a")
    if a == "b"
  } yield ()
}

Problem

a is actually used, but it's reported as unused

[warn] src.scala:3:5: parameter a in anonymous function is never used
[warn]     a <- Some("a")
[warn]     ^
[warn] one warning found
esgott commented 7 months ago

Actually, you don't even need the better-monadic-for plugin. I assumed it must be in connection with that, but the warning is there even without that.

som-snytt commented 7 months ago

Duplicates https://github.com/scala/bug/issues/10287