Need Way More Warnings

432 views
Skip to first unread message

phkoester

unread,
Sep 10, 2012, 2:55:59 PM9/10/12
to scala...@googlegroups.com
The Scala compiler never warns me about unused methods, parameters, local variables, and such.

If you want to use a language in a production environment with large teams---and that is where I eventually want to go---, such warnings are vital. Are there really no plans to incorporate those, or have they always been deemed as yet-to-do?

I mean, now would definitely be the time to implement them. Basically, I want all the warnings the Java compiler can issue and are configurable in Eclipse in the "Unnecessary code" section.

Please. :)

Alec Zorab

unread,
Sep 10, 2012, 2:58:19 PM9/10/12
to phkoester, scala...@googlegroups.com

My ide tells me about unused local variables, but it's important to remember that scala defaults to public accessibility, so those "unused" methods are actually part of your public api.

HamsterofDeath

unread,
Sep 10, 2012, 3:00:34 PM9/10/12
to scala...@googlegroups.com
that's what ides are for. intellij idea has some inspections. don't know
about eclipse.
the compiler is not the right place for this, since a) it would slow
down the process b) you want this to be configurable, so you need to set
it up in your ide anyway (or fiddle with XML)

phkoester

unread,
Sep 10, 2012, 4:15:16 PM9/10/12
to scala...@googlegroups.com
No, that's not what IDEs are for. Warnings are to be issued by the compiler, dude.

I'm an Eclipse die-hard, don't know much about IntelliJ. But on the console I use Maven, and that's where I want to see the warnings. Ideally both in the IDE and on the console, but it's the console that matters in the end.

Som Snytt

unread,
Sep 10, 2012, 4:48:02 PM9/10/12
to phkoester, scala...@googlegroups.com
I was hoping something had got put behind -Xlint, but this is a case where Xlint wouldn't have told you that.

I forgot to shift my magic number by my very private lucky factor, but got no unused warning under -Xlint -Ywarn-all.

Maybe -Ywarn-all means, "why warn at all?"

If it's any consolation, under -optimise, it won't optimise anything away, either.

object Foo {
  // not a compile-time constant, because it used to be 8 every other Tuesday, but I took that out
  // because I wasn't sure it was helping.
  private [this] final val futz: Int = 7

Clint Gilbert

unread,
Sep 10, 2012, 4:57:44 PM9/10/12
to scala...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Is it possible to make the stock Oracle javac emit unused
method/variable errors? I didn't see anything about that here:

http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html#nonstandard

though I am by no means an expert.

Where I work, in addition to our IDEs, we've always used Sonar (which
runs CheckStyle and FindBugs) for warning on things like unused
variables and methods in Java sources. That's not yet a great option
for Scala though.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlBOVEgACgkQ5IyIbnMUeTspNgCcD+YwSMp924v6EDvFaB8aKywa
hmwAn1yehAT3gsZXUC9qCPA/CppR3LZT
=zZHC
-----END PGP SIGNATURE-----

HamsterofDeath

unread,
Sep 10, 2012, 5:09:20 PM9/10/12
to scala...@googlegroups.com
i disagree: yes, it is what they are for. intellij has a ton (literally)
of inspections. for all kinds of stuff, not just possible bugs. then
there's PMD, findbugs and some more tools i might not have heard of. i
don't want to see a log with 5k warnings, i want to see them on the fly
while looking at code, being offered quickfixes, having a way to let a
scan run on the complete source if i want to and the result should be
nicely readable.
lettings all inspections i use run on a 10k classes project can take
hours. compiling it takes a minute. no, i do not want the compiler to
spam warnings into the console and take hours. a compiler should warn
about what is *obivously* wrong or very dangerous or maybe even refuse
to compile it, but it's not a code inspector.

√iktor Ҡlang

unread,
Sep 10, 2012, 5:15:18 PM9/10/12
to Som Snytt, phkoester, scala...@googlegroups.com
On Mon, Sep 10, 2012 at 10:48 PM, Som Snytt <som....@gmail.com> wrote:
I was hoping something had got put behind -Xlint, but this is a case where Xlint wouldn't have told you that.

I forgot to shift my magic number by my very private lucky factor, but got no unused warning under -Xlint -Ywarn-all.

Maybe -Ywarn-all means, "why warn at all?"

If it's any consolation, under -optimise, it won't optimise anything away, either.

object Foo {
  // not a compile-time constant, because it used to be 8 every other Tuesday, but I took that out
  // because I wasn't sure it was helping.
  private [this] final val futz: Int = 7

}

Leave out the type ascription and it will be a constant.

Cheers,
 


On Mon, Sep 10, 2012 at 1:15 PM, phkoester <beebl...@googlemail.com> wrote:
No, that's not what IDEs are for. Warnings are to be issued by the compiler, dude.

I'm an Eclipse die-hard, don't know much about IntelliJ. But on the console I use Maven, and that's where I want to see the warnings. Ideally both in the IDE and on the console, but it's the console that matters in the end.





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Philip Köster

unread,
Sep 10, 2012, 5:20:02 PM9/10/12
to HamsterofDeath, scala...@googlegroups.com
> i disagree: yes, it is what they are for. intellij has a ton
(literally) of inspections.

That may be so. So you use IntelliJ, I use Eclipse, so who is wrong or
right? In the end it's the Odersky compiler. Not everybody in your team
may be using IntelliJ. Neither may be Jenkins or Bamboo. Not having
warnings for unused private fields or warnings is ridiculous, regardless
of the IDE.

phkoester

unread,
Sep 10, 2012, 5:24:15 PM9/10/12
to scala...@googlegroups.com, HamsterofDeath, beebl...@googlemail.com
Sorry for the obvious typo.

HamsterofDeath

unread,
Sep 10, 2012, 5:40:48 PM9/10/12
to Philip Köster, scala...@googlegroups.com
there are always exceptions. for example, if you use reflection for
whatever reason, you might have private fields which are never set, and
a smart compiler might warn you about them. but that would be wrong. you
need more information to make the warnings useful. in my ide, i can say
"in this package, i know that unused parameters are ok because these are
default values which can be used in subclasses". how to tell that to a
compiler? it cannot handle every possible case, let alone offer a
convenient way to configure all of this.
intellij has a lot of knowledge about many frameworks. it understands
springs autowired annotation. if i forget the annotation: warning. if
it's there: no warning. it understands GWTs native javascript methods.
if i call a java method from javascript: no warning. if i don't call it:
warning. a compiler simply cannot keep up with all this.
a compiler should stick to compiling, and be good at it. it may warn
about totally obvious things like unused parameters in private methods,
conditions which are guaranteed to be constant - the basic stuff.

Clint Gilbert

unread,
Sep 10, 2012, 6:00:45 PM9/10/12
to scala...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This isn't either/or. There's a need for both visually-indicated
warnings and an IDE and textual warnings in some scriptable,
command-line tool.

The reference compiler is not the place to implement the latter. For
that, I'd love to see better support for Scala in Sonar, FindBugs,
CheckStyle and their ilk, or new, similarly capable tools.

I've found these:

http://docs.codehaus.org/display/SONAR/Scala+Plugin
https://github.com/scalastyle/scalastyle
https://github.com/foursquare/linter

But they're all a bit limited. Is there anything else out there in the
Scala static-analysis space? Something that gives comparable output to
what Sonar provides for Java would be very, very nice.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlBOYw0ACgkQ5IyIbnMUeTvIsACfZnHAzHGafw80QaMYh6EGLm3r
5uYAn25dwWYkzNNU5FFGcfR3BhwoNv6U
=CU/h
-----END PGP SIGNATURE-----

Som Snytt

unread,
Sep 10, 2012, 8:10:50 PM9/10/12
to √iktor Ҡlang, phkoester, scala...@googlegroups.com
On Mon, Sep 10, 2012 at 2:15 PM, √iktor Ҡlang <viktor...@gmail.com> wrote:


On Mon, Sep 10, 2012 at 10:48 PM, Som Snytt <som....@gmail.com> wrote:


object Foo {
  // not a compile-time constant, because it used to be 8 every other Tuesday, but I took that out
  // because I wasn't sure it was helping.
  private [this] final val futz: Int = 7

}

Leave out the type ascription and it will be a constant.


Thanks.  But you see, I didn't want a constant because I needed to switch from Tuesdays to Thursdays without recompiling the many clients of my magic8ball.jar. 

But here is an indicator that this is non-obvious or obscure for SO users with more than three significant digits of rep:

http://stackoverflow.com/questions/12309114/why-is-a-val-inside-an-object-not-automatically-final/12313911

The phrase I appreciate is: "Update: Actually this is more curious than I expected." 

I'm not religious about what in the tool chain does it, but eventually I would like an option

scalac -Xcuriouser -Y-and-curiouser


Reply all
Reply to author
Forward
0 new messages