-
Notifications
You must be signed in to change notification settings - Fork 18
bogus io.EOF error when error var is predeclared #15
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
Similarly, for existing code in @@ -113,7 +114,9 @@ type CompressedFile struct {
}
func (c CompressedFile) Read(p []byte) (int, error) {
- n, err := c.reader.Read(p)
+ var n int
+ var err error
+ n, err = c.reader.Read(p)
if err == io.EOF {
return n, io.EOF
} |
Happens because |
The allowed error set is implemented by checking comparisons for whether an error is returned from a known safe function. The current implementation uses the declaration of the error variable to see whether it comes from such a function. In your case, the declaration is a variable declaration without initialisation for which no logic is implemented yet. We can fix this by not only checking the declaration, but also the last assignment to the error variable. Checking only the last assignment also requires understanding the control flow, which would make this linter way more complex than I am able to support. So I would propose an implementation which just checks all assigning expressions instead. Will do some hacking when I have time, unless someone beats me to it :P |
@kolyshkin I have pushed a fix to branch |
I have done some more testing on my own projects and it seems to work well. Merged my changes :) |
I have previously submitted #12 hoping it would fix to eliminate a bogus error in my code.
Today I found it did not.
The following code is fine (i.e. no warnings):
but if we modify it in this way:
we will have something like
and this code results in a warning:
Alas, I don't know internals good enough to try to fix it.
The text was updated successfully, but these errors were encountered: