-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
staticcheck: SA5011 false positive #641
Comments
It is a false positive, and we could make an effort to avoid it, but it's not a high priority to me. I'd prefer if people took it as a suggestion to remove the unnecessary nil check instead. Is this false positive occurring in a context where an unnecessary check cannot be removed? |
I think the unnecessary check can be removed. This is the context: edwood/acme.go (some really old C code that's been ported to Go). |
I am going to close this issue as "working as designed". The check flags interactions of pointer dereferences and nil pointer checks, and it is correct in stating that the check suggests the possible presence of a nil pointer. Removing the impossible nil pointer check is the correct fix here. |
* Remove a redundant nil check that confuses staticcheck. See dominikh/go-tools#641 * Remove some unnecessary use of fmt.Sprintf. * Ignore one problem in a file copied from standard library.
* Remove a redundant nil check that confuses staticcheck. See dominikh/go-tools#641 * Remove some unnecessary use of fmt.Sprintf. * Ignore one problem in a file copied from standard library.
Just got bit by something related - staticcheck complained of a possible nil dereference, so I added a check at the top of the function. It kept on complaining, which made me think it somehow didn't understand the nil check. Only after reading this issue did I notice there was a second nil check later in the function, below the lines it'd complained about. Would it be possible to update the message? Maybe something like -possible nil pointer dereference (SA5011)
+possible nil pointer dereference (or extra nil check below) (SA5011) I'm using staticcheck as bundled in
|
@mpictor when running
it outputs the following diagnostic
pointing at both the dereference, as well as the relevant nil pointer check. It seems that golangci-lint neglects to point at the actual check:
This is an issue in golangci-lint, not staticcheck. In |
thanks for looking @dominikh, I'll ask golangci-lint to fix |
Running staticcheck on this program:
Gives this output:
t
will not benil
because of the check before it's being used. Staticcheck is being fooled by the second check.The text was updated successfully, but these errors were encountered: