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

"parameter value .. is never used" with if in for #32

Open
Daenyth opened this issue Jul 18, 2019 · 4 comments
Open

"parameter value .. is never used" with if in for #32

Daenyth opened this issue Jul 18, 2019 · 4 comments
Labels
question Further information is requested

Comments

@Daenyth
Copy link
Contributor

Daenyth commented Jul 18, 2019

This code:

val x =
 for {
    n <- Some(1)
    if n > 0
  } yield n

triggers the "unused parameter" lint:

Error:(99, 7) parameter value n in value $anonfun is never used
      n <- Some(1)
@oleg-py
Copy link
Owner

oleg-py commented Jul 19, 2019

I can't reproduce that. Which version of bm4, Scala and combination of flags are you using?

@oleg-py oleg-py added the question Further information is requested label Jul 19, 2019
@Daenyth
Copy link
Contributor Author

Daenyth commented Jul 19, 2019

scala 2.12.8, bm4 0.3.0, "io.github.davidgregory084" % "sbt-tpolecat" % "0.1.7" for flags

@oleg-py
Copy link
Owner

oleg-py commented Oct 11, 2019

Seems -Ywarn-unused:params is just busted irrespective of plugin. E.g. it warns in this simple case:

object test extends App {
  val x =
    for {
      n <- Some(1)
      if n > 0
    } yield "Sup"
  println(x)
}

(scastie, but you might need to edit a code to trigger a recompile with full warnings), and if you do yield n, it's not reproducible on 0.3.1 with code you've provided.

@nigredo-tori
Copy link

@oleg-py, that expression has to be desugared into something like

Some(1).filter(n => n > 0).map(n => "Sup")

, which probably makes determining "whether n is used" difficult (since there is no single n). There are issues about this behavior, but they don't seem to going anywhere. And I see no good way to work around this in a plugin without changing semantics (by getting something more than filter and map to work with), or disabling this lint.

Looks like we'll just have to write it like this for the foreseeable future:

for {
  _ <- Some(1).filter(n => n > 0)
} yield "Sup"

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

No branches or pull requests

3 participants