Skip to content
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

False negatives with io.Closer #18

Open
muravjov opened this issue Aug 14, 2019 · 0 comments
Open

False negatives with io.Closer #18

muravjov opened this issue Aug 14, 2019 · 0 comments

Comments

@muravjov
Copy link

Hello, the following code is good, but bodyclose finds it bad:

$ git diff
diff --git a/passes/bodyclose/testdata/src/a/a.go b/passes/bodyclose/testdata/src/a/a.go
index dcf9448..da0c7cd 100644
--- a/passes/bodyclose/testdata/src/a/a.go
+++ b/passes/bodyclose/testdata/src/a/a.go
@@ -2,6 +2,7 @@ package a
 
 import (
        "fmt"
+       "io"
        "net/http"
 )
 
@@ -83,6 +84,14 @@ func f7() {
        resCloser()
 }
 
+func f7c() {
+       res, _ := http.Get("http://example.com/") // OK
+       resCloser := func(c io.Closer) {
+               c.Close()
+       }
+       resCloser(res.Body)
+}
+
 func f8() {
        res, _ := http.Get("http://example.com/") // want "response body must be closed"
        _ = func() {
$ GO111MODULE=on go test -v github.com/timakin/bodyclose/passes/bodyclose
=== RUN   Test
--- FAIL: Test (1.51s)
    analysistest.go:251: a/a.go:88:20: unexpected diagnostic: response body must be closed
FAIL
FAIL    github.com/timakin/bodyclose/passes/bodyclose   1.529s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant