-
Notifications
You must be signed in to change notification settings - Fork 138
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
Check for reassignment before use. #7
Comments
Thanks for the great package! We run errcheck as part of our continuous build at work. I'm interested in getting this case covered, but it seems like it may be tough. It does seem like the best way would be to use SSA (btw, check out this ssa viewer: http://golang-ssaview.herokuapp.com/), but that seems like it would require basically starting from scratch. Did you have any subsequent thoughts on the matter (I see this was opened long ago)? Do you think it would be preferable to implement all of errcheck using SSA anyway? (As an aside, I wonder if it would be faster that way -- it already takes 40+ seconds to check ~20k lines of code.) |
Glad to hear it's working well for you :) I have definitely thought about this some more, but rewriting the whole program using SSA just for this is a lot of work for what is likely very little gain. I'm not sure how much of a performance gain it would yield either. 40+ seconds for 20k lines seems like a long time, the Go standard library takes under 4 seconds to check on my machine. |
The 40+ seconds happens on both Darwin & Linux, laptop and workstation, so I don't think it's a quirk of my setup. FWIW, the Go std library checks quickly for me too. Maybe errcheck has to scan all dependencies as well, which would include standard library, plus the ~50 third-party packages that we use. |
Yes, I'm pretty sure the type analysis done by go.types needs to include all dependencies as well. I don't think using SSA would eliminate this since we would still need type analysis to determine which return values are errors. |
That's too bad. In theory, it should be sufficient to look only at the signatures of functions that are directly called (the first degree dependencies). That should be much faster than constructing the AST for my entire GOPATH |
hm yes, that's true. I'll have to look in to it some more when I have time, I'm pretty sure when I originally wrote errcheck that wasn't possible to do. |
but the APIs of all the type-related packages have evolved a lot since then. |
Also it would be nice to catch unhandled error in this example:
|
I agree. Will have to learn about using the SSA package to figure out how
|
this tool does something similar https://github.com/gordonklaus/ineffassign . I can catch example from first comment. |
https://github.com/dominikh/go-staticcheck catches this sort of thing, FWIW. |
@kisielk should we close this, given that staticcheck has it covered? |
I think it still falls in the scope of this package, maybe it will get added at some point |
Here's a test case for potential reassignment: 8320fd2f |
It would be nice to catch code such as:
This is not an error according to the compiler: http://play.golang.org/p/3DJj2e3-8L
The upcoming ssa package would likely be useful here.
The text was updated successfully, but these errors were encountered: