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

suppress unchecked warnings globally #1781

Closed
scabug opened this issue Mar 9, 2009 · 13 comments
Closed

suppress unchecked warnings globally #1781

scabug opened this issue Mar 9, 2009 · 13 comments

Comments

@scabug
Copy link

scabug commented Mar 9, 2009

Currently, Scala supports suppressing unchecked warning only for single expression:

(x: @unchecked) match { ... }

However, some classes (test cases, for example) tend to have many places where unchecked warnings arise. There should be a way to disable unchecked warnings for the whole class, like this:

@unchecked
object MyTests { ... }

or disable unchecked warnings for the whole compiler run:

scalac -ignore-unchecked
<scalac unchecked="ignore" ... />
@scabug
Copy link
Author

scabug commented Mar 9, 2009

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

@scabug
Copy link
Author

scabug commented Mar 17, 2009

@odersky said:
I think this would be too much magic. @unchecked in a match selector makes it clear what it is. In front of an object you have no idea, so we'd need a different option.
I want to be really careful not to spread out annotations too much. So I think this would be a good place for a community supplied compiler plugin, if it is really deemed that important.

@scabug
Copy link
Author

scabug commented Mar 17, 2009

@stepancheg said:
It is not magic. Standard Java annotation @SuppressWarnings("something") can be applied to class or method, and suppress specified warning in all statements inside annotated scope.

@scabug
Copy link
Author

scabug commented Mar 24, 2009

@dragos said:
Discussed in today's meeting, and Martin concluded this is not worth the gain.

@scabug
Copy link
Author

scabug commented Jul 7, 2011

@paulp said:
We need some way of suppressing warnings which cannot otherwise be eliminated.

@scabug
Copy link
Author

scabug commented Jun 11, 2012

@adriaanm said:
Maybe we can use the -feature flag for this.

@scabug
Copy link
Author

scabug commented Jul 3, 2012

@paulp said:
Since this has been closed again, noting for the record that the philosophy that generating warnings is fine but suppressing the noise is not may eventually lead your build output to look like this (obviously fictional) transcript. Had I built with -optimise in this fictional project then we'd really have not-seen some warnings.

[scalacfork] warning: there were 59 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 12 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 7 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] warning: there were 18 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 3 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 14 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] /scratch/trunk4/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala:339: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
[scalacfork] /scratch/trunk4/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala:339: warning: enclosing method BeginExceptionBlock has result type Unit: return value discarded
[scalacfork] warning: there were 3 unchecked warnings; re-run with -unchecked for details
[scalacfork] three warnings found
[scalacfork] warning: there were 70 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 23 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 21 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] warning: there were 59 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 12 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 7 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] warning: there were 25 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 6 feature warnings; re-run with -feature for details
[scalacfork] two warnings found
[scalacfork] warning: there were 1 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 19 feature warnings; re-run with -feature for details
[scalacfork] two warnings found
[scalacfork] warning: there were 18 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 3 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 14 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] /scratch/trunk4/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala:339: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
[scalacfork] /scratch/trunk4/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala:339: warning: enclosing method BeginExceptionBlock has result type Unit: return value discarded
[scalacfork] warning: there were 3 unchecked warnings; re-run with -unchecked for details
[scalacfork] three warnings found
[scalacfork] warning: there were 70 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 23 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 21 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] warning: there were 1 feature warnings; re-run with -feature for details
[scalacfork] one warning found
[scalacfork] warning: there were 24 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 5 feature warnings; re-run with -feature for details
[scalacfork] two warnings found
[scalacfork] warning: there were 46 feature warnings; re-run with -feature for details
[scalacfork] one warning found
[scalacfork] warning: there were 65 feature warnings; re-run with -feature for details
[scalacfork] one warning found
[scalacfork] warning: there were 3 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 28 feature warnings; re-run with -feature for details
[scalacfork] two warnings found
[scalacfork] warning: there were 59 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 12 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 7 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] warning: there were 25 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 6 feature warnings; re-run with -feature for details
[scalacfork] two warnings found
[scalacfork] warning: there were 1 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 19 feature warnings; re-run with -feature for details
[scalacfork] two warnings found
[scalacfork] warning: there were 18 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 3 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 14 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] /scratch/trunk4/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala:339: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
[scalacfork] /scratch/trunk4/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala:339: warning: enclosing method BeginExceptionBlock has result type Unit: return value discarded
[scalacfork] warning: there were 3 unchecked warnings; re-run with -unchecked for details
[scalacfork] three warnings found
[scalacfork] warning: there were 70 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 23 unchecked warnings; re-run with -unchecked for details
[scalacfork] warning: there were 21 feature warnings; re-run with -feature for details
[scalacfork] three warnings found
[scalacfork] warning: there were 1 feature warnings; re-run with -feature for details
[scalacfork] one warning found
[scalacfork] warning: there were 46 feature warnings; re-run with -feature for details
[scalacfork] one warning found
[scalacfork] warning: there were 65 feature warnings; re-run with -feature for details
[scalacfork] one warning found
[scalacfork] warning: there were 3 deprecation warnings; re-run with -deprecation for details
[scalacfork] warning: there were 28 feature warnings; re-run with -feature for details
[scalacfork] two warnings found

@scabug
Copy link
Author

scabug commented Jul 4, 2012

@adriaanm said (edited on Jul 4, 2012 9:25:22 AM UTC):
The problem addressed by this ticket, as I understand it, is that spurious warnings induce the broken window effect
(once one window of some decrepit building has been broken, others are sure to follow soon).

So, I agree we should not emit warnings that cannot be fixed nor turned off in the first place,
(or we could have a switch for that, but only for those unflushable warnings).

I don't think we should provide a way to turn off all unchecked warnings.
If we give ourselves that cop out, we won't see real warnings when they re-appear,
(not due to the amount of irrelevant broken windows, but because we turned off the lights entirely).

So, yes, the right/hard approach shouldn't be a 'won't fix', but I don't even know who to assign this to right now.

@scabug
Copy link
Author

scabug commented Jul 4, 2012

@paulp said:
But the whole problem is the warnings which there is no way to eliminate. It was perhaps a mistake to reopen this ticket, because the original submitter wants to suppress unchecked warnings in a possibly irresponsible way. I want to suppress the ones which either cannot be suppressed at all, or which are the best way to do something. I want to SUPPRESS warnings because I want to HEAR MORE warnings. "There were 51 unchecked warnings" is not hearing.

Here's the sanity test of everyone's position: why isn't -unchecked on by default? It sure as hell should be. There is no more frequently answered question than "why doesn't this match work", and the transcript almost always shows that nice ignorable "there were unchecked warnings." But to do that we have to make it easy for people to suppress them, because there is still no other way in some cases, and certainly there's no comparably aesthetic way in others.

To be burying all of the unchecked warnings because we don't want people to bury some of them is the epitome of "we had to destroy the village in order to save it."

@scabug
Copy link
Author

scabug commented May 28, 2013

Chris Fuller (cfuller) said:
+1

Some of us have the discipline to respect warnings for what they are and address them from code wherever possible. The reality is that this is not always possible. Projects generally have to consume external code either in the form of an API that they integrate with or third-party libraries that they consume, and where these break the rules (such as by marking a class as deprecated without providing a replacement yet or exposing raw types), your own code is forced to break them as well to interact with them.

Not offering any way to acknowledge the situation and suppress it from the output seriously harms the signal-to-noise ratio, with the result that developers are eventually forced to ignore all warnings completely for their own sanity, because they have no way to distinguish warnings that are new and should be fixed immediately from those that are known and cannot currently be addressed.

@scabug
Copy link
Author

scabug commented Jul 11, 2013

Bas van den Broek (basvandenbroek) said:
Just commenting because I would also really really like a way to suppress a certain warning. There are 2 deprecation warnings in my project that I simply CANNOT get rid off (the code called is not in my hands) and currently I simply have to disable all deprecation warnings just to not go mad by having to check whether the warnings in my project are only in that specific class.

@scabug
Copy link
Author

scabug commented Jul 12, 2013

@som-snytt said:
If by "not in my hands" you mean "not compiled by me", then invoking it from a local deprecated def will suppress the warning:

scala> @deprecated("","") def f = 8
f: Int

scala> f
<console>:9: warning: method f is deprecated: 
              f
              ^
scala> object A {
     | def a = {
     | @deprecated("","") def _f = f
     | _f
     | }}
defined object A

scala> A.a
res1: Int = 8

I've forgotten now whether that was a feature or a bug. I think a feature, because local defs are not API and therefore cannot be deprecated, so invoking them cannot warn. However, marking them deprecated says the call stack is polluted with deprecations thereafter, but you know what you're doing. It's the asInstanceOf for deprecations.

This came up again, in the context of wanting -Xfatal-warnings for only some warnings, or conversely, -Xfatal-warnings but with certain unavoidable warnings suppressed.

http://stackoverflow.com/a/17506410/1296806

@scabug
Copy link
Author

scabug commented Oct 25, 2013

Topher (topher.the.geek) said:
I'm left confused here. I want to suppress deprecation warnings over a limited scope, for exactly the reasons identified above. This bug's title asks to suppress unchecked warnings globally, which I don't want to vote for, but the conversation has clearly moved to suppress deprecation warnings over a limited scope, which I do want to vote for.

For clarity, I've opened a new bug for that focused need: #7934.

I'd suggest closing this bug as "Won't fix." That's a fine response to the request "suppress unchecked warnings globally." As for everyone who voted for this bug because they wanted "suppress deprecation warnings over a limited scope," I encourage you to head over to the new bug and vote for it.

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

1 participant