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

Add linting of unused context bounds (via -Wunused:synthetics or -Wunused:params) #9346

Merged
merged 1 commit into from Jan 15, 2021

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Nov 25, 2020

Warn under -Wunused:synthetics which is included by -Wunused:params.

Warnings for unused value parameters can be selectively enabled. -Xlint enables -Wunused:implicits to warn about unused implicit parameters. Warnings about ordinary parameters can be enabled with -Wunused:explicits; that is deemed noisy for ordinary use, so it is not enabled by -Xlint. Now, "unused context bounds", which are synthetic parameters, can be detected by enabling -Wunused:synthetics. All three warnings are enabled by -Wunused:params.

  def f[A](implicit ctx: Context[A]) = ???  // -Wunused:implicits
  def g[A: Context] = ???                   // -Wunused:synthetics

Fixes scala/bug#10349

@scala-jenkins scala-jenkins added this to the 2.13.5 milestone Nov 25, 2020
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Dec 4, 2020
@SethTisue
Copy link
Member

@som-snytt this appears just about ready to merge, but because it adds a new flag, would you mind supplying a nice PR description that explains this from the user's point of view (and without requiring them to follow links), for linking from the release notes? in particular, I'm wondering what the recommended way of suppressing the warning is (and should there be a test that tests that?), since @unused won't work here since there's nowhere to put it.

@dwijnand dwijnand merged commit 1013b54 into scala:2.13.x Jan 15, 2021
@dwijnand
Copy link
Member

in particular, I'm wondering what the recommended way of suppressing the warning is (and should there be a test that tests that?), since @unused won't work here since there's nowhere to put it.

I merged it already, but I think this would be handy to have written down. 🤗

@SethTisue
Copy link
Member

I'm always a little hesitant about letting flags proliferate, but this is an area where it's probably harmless and will benefit at least some users.

I just had a look at sbt-tpolecat and it does enable -Wunused:params, so that means this change will automatically get some uptake/testing once 2.13.5 is released. (And sbt-tpolecat users aren't too put off by occasional false positives.)

@som-snytt som-snytt deleted the issue/10349 branch January 15, 2021 18:07
@SethTisue SethTisue changed the title Lint option for unused context bounds Add linting of unused context bounds (via -Wunused:synthetics or -Wunused:params) Feb 19, 2021
@SethTisue
Copy link
Member

SethTisue commented Feb 25, 2021

OH: “I just eliminated six unused constraints”, not sure who it was, but it sounded like they were wearing ski goggles, relative of yours @tpolecat?

oh heh nm, I see you thanked him on Gitter 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
4 participants