Skip to content

Missing unused warnings for lambdas parameters #20951

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
mbovel opened this issue Jul 2, 2024 · 4 comments · Fixed by #20894
Closed

Missing unused warnings for lambdas parameters #20951

mbovel opened this issue Jul 2, 2024 · 4 comments · Fixed by #20894
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@mbovel
Copy link
Member

mbovel commented Jul 2, 2024

In Scala 2.13:

object Foo {
  val dummy = 42
  def f(): Unit = Option(1).map((x: Int) => dummy)
  def main(args: Array[String]): Unit = {}
}
➜  ~/scala-snippets-6 scala-cli -Ywarn-unused -S 2.13 warning_lamdas.scala
[warn] ./warning_lamdas.scala:3:34
[warn] parameter x in anonymous function is never used
[warn]   def f(): Unit = Option(1).map((x: Int) => dummy)

In Scala 3, no warning.

Might be due to #17223.

@mbovel mbovel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 2, 2024
@jan-pieter
Copy link
Contributor

@mbovel I couldn't let go and have taken a stab at this in #20973 😉. WDYT?

@Gedochao Gedochao added area:linting Linting warnings enabled with -W or -Xlint and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 3, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Jul 3, 2024

@mbovel what should be the flag to be passed to the Scala 3 compiler, when the warning should be logged?
-Wunused:all and -Wunused:params?

@som-snytt
Copy link
Contributor

I know I encountered this while enabling lints on the scala 2 code base. Sorry I don't have a link, but I'll add it if I find it.

I think my conclusion was, "naming is hard, avoid it if you can."

xs.map((_: Int) => f) // let's say the type is required

Since naming is a cost (like anything else), penalize it!

"If you name it, use it!"

If Scala had a mascot, Scala Center could commission a poster showing the mascot with that slogan. Like Smokey Bear saying only you can prevent forest fires.

@som-snytt
Copy link
Contributor

Lambda parameters will warn even for trivial bodies. x => ???.

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
4 participants