-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/tools/go/analysis/passes/nilness: no position information with error #31008
Comments
/cc @matloob |
This is a major problem that deserves attention. I work for a medium sized tech company looking to adopt golangci-lint and this issue is holding me back. |
Indexed range loops are lacking position data in their SSA representation, so add the position data into an index operation This improves the problem described in golang/go#31008 by providing position data with the nilness message
Change https://golang.org/cl/208599 mentions this issue: |
Indexed range loops are lacking position data in their SSA representation, so add the position data into an index operation. This improves the nilness output by providing position data with the message. Updates golang/go#31008 Change-Id: I664c8668bc74207e770657e21129d20fd70e7af6 GitHub-Last-Rev: 75831d2 GitHub-Pull-Request: #190 Reviewed-on: https://go-review.googlesource.com/c/tools/+/208599 Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
@vovapi's CL above adds position information to the error message, but I think to improve this further we'd have alter the way go/ssa tracks position information. Something similar was done for staticcheck: dominikh/go-tools@c14c261 |
Thought it might be worth adding a case where the nilness analyzer fails to provide position information where it seemingly should do so. func do(a interface{}) {
switch a.(type) {
case nil:
return
}
switch a.(type) {
case nil:
return
}
} https://go.dev/play/p/3K_9FFGOWzd
|
Change https://go.dev/cl/394694 mentions this issue: |
This allows better reporting in passes, such as nilness. Updates golang/go#31008 Change-Id: Ie188844b550bf2b924747f3ac476dd6feeda6d6c Reviewed-on: https://go-review.googlesource.com/c/tools/+/394694 Run-TryBot: Zvonimir Pavlinovic <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]> Trust: Zvonimir Pavlinovic <[email protected]>
Change https://go.dev/cl/394694 should have now addressed the issue with positions in case conditions. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Ran the nilness analyzer on this (simplified) package:
What did you expect to see?
Ideally: a different error about how you're iterating over a nil slice
Less ideally: the same error, but with information telling me where the error is
What did you see instead?
-: nil dereference in index operation
This kind of error is pretty hard to track down if I'm running the analyzer over a large codebase, because it doesn't say which file or package is failing.
The text was updated successfully, but these errors were encountered: