I want to propose a way to suppress -Wvalue-discard and -Wnounit-statement at the definition site. Best name for the annotation I came up with is @AllowDiscard, but in Java land the more common naming is way more verbose @CanIgnoreReturnValue.
The annotation can be used
- On classes / enums, signifying that this class is not very meaningful as a return value. Few examples are scala.js
js.Dynamic, an enum containing error codes, quasi-fluent-style classes returningthisin every method… - On methods, signifying it’s okay for the method caller to ignore the return value. Examples are various update methods that return the updated value (example from Java land
ConcurrentHashMap.computeIfAbsent), or other ignorable information (for exampleHashMap.remove(k, v)boolean), etc..
I am not yet sure how to suppress these things on existing Java library classes.
After this, we should start thinking to make these warnings turned on by default, as they actually catch human mistakes.