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

-Wunused:params don't work for unimplemented methods #12592

Closed
gatisnolv opened this issue May 12, 2022 · 6 comments
Closed

-Wunused:params don't work for unimplemented methods #12592

gatisnolv opened this issue May 12, 2022 · 6 comments

Comments

@gatisnolv
Copy link

Reproduction steps

Scala version: 2.13.8

  object Example {
    def unusedImplicit(implicit i: Int) = ???

    def unusedExplicit(i: Int) = ???

    def unusedContextBound[A: Ordered] = ???
  }

with the compiler option
"-Wunused:params"

(or with "-Wunused:explicits", "-Wunused:implicits", "-Wunused:synthetics")

Problem

I expect the unused implicit, explicit and context bound parameters to be reported as 'never used' for each method respectively, but there are no warnings for these unimplemented methods (so the specific example in the implementing PR does not actually produce warnings, as those methods are also unimplemented with ???). If the methods are implemented to e.g. return 1, the expected warnings are produced.

@gatisnolv gatisnolv changed the title "-Wunused:params" don't work for unimplemented methods -Wunused:params don't work for unimplemented methods May 12, 2022
@SethTisue
Copy link
Member

@som-snytt I feel like I'm vaguely remembering you did this intentionally?

@som-snytt
Copy link

Yes, that is a long-time feature that was recently augmented under #11856

Maybe when the compiler options page is refreshed, linting behavior could be expanded upon, or I guess the word is expatiated. Although there lints that can be selected, the general goal is to avoid many knobs and levers, and find a sweet spot that is useful but not noisy, so that Xlint can be ordinarily enabled.

Maybe someone will get back to scala/docs.scala-lang#1711

@gatisnolv
Copy link
Author

@som-snytt So just to clarify - it's intended behavior, that in the case of unimplemented methods (with '???') these parameters are not being reported as unused, correct?

@som-snytt
Copy link

Yes, that is a long-time feature that was recently augmented under #11856

@SethTisue
Copy link
Member

SethTisue commented Sep 22, 2022

The design justification is that ??? indicates explicit intent on the part of the user not to fill in an implementation. In general, warnings aim to catch accidents, not obstruct willful action.

If that design decision doesn't suit your codebase's needs, consider adding a Scalafix rule to your build (or use Wartremover or whatever) that complains if ??? is ever used at all.

@gatisnolv
Copy link
Author

Thanks, all clear now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants