-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: check for logically incorrect return based on scope and error #21848
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
Comments
The playground link doesn't work, and I'm not sure what you are suggesting. |
Github does not add the _ at the end of the play link to the actual link: |
Sorry, terrible playground I created over there. Did a correct one over here: Basically I am returning a Thanks |
Thanks. I think that you are asking for vet to look for cases where we return a value of type |
Yes, exactly. I think it's rare as well but when it happens its pretty hard to see it in the middle of all that code. Perhaps it could also be used for other types that aren't errors - making it way more useful but then it might have a performance penalty. By the way, thank you for that cmd/vet/README, hadn't seen it before :) Perhaps this can be closed as it doesn't match the "frequency" rule. Thank you |
What about:
where the panic is just for debugging? Does vet now complain that err is statically nil in the return? It seems like a very specific check. So in addition to frequency above I'd raise some questions about precision. But it seems like the consensus is already that it's too special, so closing. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.9 linux/amd 64
Does this issue reproduce with the latest release?
yes, using
go vet -all main.go
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
Ran the following program:
https://play.golang.org/p/Hu3qX6aSr-
What did you expect to see?
I (think) vet should warn about that
return err
in r.StatusCode != r.StatusOK as it will return nil.What I actually think should happen is that vet perhaps could be able to see if the error is being checked before and check if it's being returned after, where in the happy code path it will surely be nil.
The text was updated successfully, but these errors were encountered: