Skip to content

Make -Ywarn-unused:params sensitive to usages in extending classes #11343

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
som-snytt opened this issue Apr 6, 2017 · 8 comments
Closed

Make -Ywarn-unused:params sensitive to usages in extending classes #11343

som-snytt opened this issue Apr 6, 2017 · 8 comments
Assignees
Milestone

Comments

@som-snytt
Copy link

Tweaks to linting params as noted by @lrytz on community build.

$ skala -Xlint -Ywarn-unused
Welcome to Scala 2.12.2-20170406-193519-6614931 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> def f(x: Int)(y: Int = 1) = x + y
<console>:11: warning: parameter value x in method f$default$2 is never used
       def f(x: Int)(y: Int = 1) = x + y
             ^
f: (x: Int)(y: Int)Int

scala> :pa
// Entering paste mode (ctrl-D to finish)

class C { def f(x: Int, y: Int) = y }
class D extends C { override def f(x: Int, y: Int) = x + y }

// Exiting paste mode, now interpreting.

<pastie>:11: warning: parameter value x in method f is never used
       class C { def f(x: Int, y: Int) = y }
                       ^
defined class C
defined class D
@som-snytt
Copy link
Author

som-snytt commented Apr 7, 2017

scala/scala#5402 for default getters

@SethTisue SethTisue transferred this issue from scala/scala-dev Jan 9, 2019
@SethTisue SethTisue added this to the Backlog milestone Jan 9, 2019
@SethTisue
Copy link
Member

@som-snytt should this stay open? I transferred it from scala-dev

@som-snytt
Copy link
Author

The second case still warns. The improvement is to (optionally) warn only for sealed or final classes, if param is used in no override. Don't warn (optionally) for abstract classes.

@som-snytt
Copy link
Author

Relatedly, unused ctor of "effectively sealed" (sealed/private) class does not warn. Under the rubric of things to notice about such classes.

@SethTisue
Copy link
Member

SethTisue commented Feb 19, 2023

The second case still warns

I would not consider that a bug. Or rather, I would require convincing?

The parameter is in fact unused. The fact that D does something different seems irrelevant to me.

Scala 3 also warns in this case.

The improvement is to (optionally) warn only for sealed or final classes, if param is used in no override

I doubt this level of ambition is desirable.

There aren't other places in unused analysis where you do this kind of inter-class analysis.... are there?

@SethTisue SethTisue changed the title Improve -Ywarn-unused:params Make -Ywarn-unused:params sensitive to usages in extending classes Feb 19, 2023
@som-snytt
Copy link
Author

The sentiment at one point (maybe Jason said something) was that warning for unused params would be too noisy to be useful.

I would like all the unused warnings to be lints, just because remembering which are enabled by -Xlint is an encumbrance. That is possible if they work well with some heuristics (which can be turned off).

@SethTisue
Copy link
Member

Hmm. Maybe in Scala 3 I'll conclude that -Wunused:all casts too wide a net and I should enable the categories individually.

@som-snytt
Copy link
Author

Currently, an override is absolved (for unused param) because you can't change the signature you inherit.

Closing because not inclined to convince Seth (by plying him with beers). The nowarn and WConf facilities obviate too much cleverness.

Probably the other heuristics to mitigate warnings should be removed, except for simple "RHS is ???".

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
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

2 participants