Improve inferred-Any lint (fixing false positives and false negatives)#9452
Improve inferred-Any lint (fixing false positives and false negatives)#9452lrytz merged 1 commit intoscala:2.13.xfrom
Any lint (fixing false positives and false negatives)#9452Conversation
|
It seems to me the lint is correct and the signature should include the bound: Yesterday I experimented with trying to clear buffered warnings when retrying a result in typedApply, but I omitted that, since it seemed fragile given limitations of context reporting. But maybe the naive approach of always warning is worth any false positives. Probably I won't attempt anything nuanced and complicated here for limited bang/buck ratio. |
|
Here's another example that this fixes: I didn't manage to come up with a counter-example where the warning is issued in silent type checking but then the non-Any alternative is chosen, maybe someone else does? |
|
(as Dale pointed out in conversation) this is a good candidate for scala/community-build#1270 (which I set aside when it became no-longer-urgent on some other PR, but still intend to return to). |
|
Moved the clean-up tweaks to a non-controversial PR. It has to be wrong to lint code which isn't expected to compile. A useful community build would indicate how bad the false positives are, or provide a helpful example. But it's better for 9 inferences of Any to go free than for one innocent LOC to be quarantined on false witness. |
98a3a3f to
6a19a3a
Compare
|
The current behavior change is the test for 9211, which currently warns (false positive). Also adds a warning in t12441 (which was the silent warning change), where the pt is not relevant. (That would mean never warning for calls to println.) This is a simplification and improvement, a clear win. Not sure why users are not yet profiting. The warnings in test code demonstrate effectiveness. Non-test code was previously improved. The code comment mentions the line in Map to avoid warning, but that is currently linted. |
lrytz
left a comment
There was a problem hiding this comment.
LGTM. It's probably worth release-notes. Could you udpate the PR description?
|
PSA |
Any lint (fixing false positives and false negatives)
Any lint (fixing false positives and false negatives)Any lint (fixing false positives and false negatives)
-Xlint:infer-any, which is part of the default-Xlintbundle, warns if an inferred type argument is a "top" type:Any,AnyVal,AnyRef, orObject.The heuristic has been improved not to warn if a type parameter in the expression has an upper or lower bound that is a "top" type.
Typically, the warning is "silenced" by supplying an explicit type argument where needed, if the usage was intended.
It no longer considers whether the "expected type" is
Any. Previously, just passing an expression toprintlnwould silence the warning.Examples illustrating the errors to avoid:
Supplying a type argument to an infix expression is irregular syntax in Scala 2, so it may be necessary to rewrite it:
Fixes scala/bug#12320
Closes scala/bug#9211