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

Compiler should warn about unused private methods #440

Closed
scabug opened this issue Feb 4, 2008 · 11 comments
Closed

Compiler should warn about unused private methods #440

scabug opened this issue Feb 4, 2008 · 11 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Feb 4, 2008

I recently did some refactoring on my Scala code and later realized that
I had a private method that was no longer used.

It would be great if the Scala compiler could warn about these to indicate
programming errors.

For example, this should generate a warning since do_nothing is not
used.

class Test {
  private def do_nothing = 10
}

Currently, we can use findbugs to find these, but having the compiler
do them would be much nicer.

@scabug
Copy link
Author

scabug commented Feb 4, 2008

Imported From: https://issues.scala-lang.org/browse/SI-440?orig=1
Reporter: @blair

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone next_bugfix deleted

@scabug
Copy link
Author

scabug commented Jun 11, 2012

@adriaanm said:
This is more of a lint thing, as said by OP.

@scabug
Copy link
Author

scabug commented Jun 11, 2012

@blair said:
Are you suggesting that one use findbugs instead of having scalac warn you? I find this an odd resolution given there isn't a native lint tool for Scala.

@scabug
Copy link
Author

scabug commented Jun 11, 2012

@adriaanm said:
I find this odd logic. It's not because we don't have the tool that should do this, that we should add this to the tool we do have but that shouldn't do this.

@scabug
Copy link
Author

scabug commented Jun 11, 2012

@blair said:
Talk about a sentence that needs compiler to parse ;) Why shouldn't the computer warn about these?

One of the reasons people like using Clang instead of gcc/g++ to compile their code is because it gives more and better warnings and errors. I would think one would want the same from scalac. Am I missing something?

@scabug
Copy link
Author

scabug commented Jun 12, 2012

Christopher Sahnwaldt (jcsahnwaldt) said:
The Eclipse Java compiler can be configured to add warnings for unused private members. I think it can even be told to treat them as errors. Thos adds yellow or red wriggly lines in the editor. Very helpful. Don't know about the command line version.

@scabug
Copy link
Author

scabug commented Jun 12, 2012

@retronym said:
I don't disagree with Adriaan -- there are one or two lint tools in development that build on top of the compiler infrastructure (eg. scalastyle), and this would make a great feature for these.

But in the meantime, here an experimental implementation: paulp/scala@386464fe. Not really suitable for an end-user at it is based on the generated bytecode, so the warnings might refer to mangled names, etc.

BTW, IntelliJ highlights unused privates.

@scabug
Copy link
Author

scabug commented Jun 12, 2012

@adriaanm said:
From our perspective, it's yet another feature that detracts from core compiler development. From the user's perspective, compile times would go up even more (except if we put it behind a switch, of course, but then we might as well put it in a different tool).

I'd rather invest in a rich compiler "platform" that can be used by tools such as the ones Jason mentions than implement this ad-hoc analysis (no matter how useful).

This kind of analysis seems like something you would run once in a while, maybe on an integration server, or after a refactoring.

@scabug
Copy link
Author

scabug commented Jun 12, 2012

@blair said:
I agree, I'd rather see the Scala compiler developers spending time on core language features, e.g. more optimizations, that we would use all the time then a compiler warning, or a compiler platform.

The issue I had with closing the ticket was the "Out of Scope" resolution, which doesn't seem accurate, as a compiler is one place to check for programming errors. What about adding another "Will not implement" and provide the limited resources as a reason in the comment? I wouldn't have been so adamant about this issue then :)

@scabug
Copy link
Author

scabug commented Nov 2, 2012

@paulp said:
scala/scala@d0c4be6861

@scabug scabug closed this as completed Nov 2, 2012
@scabug scabug added this to the 2.11.0 milestone Apr 6, 2017
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