You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While this example is so simple as to be meaningless, the core problem comes up when trying to handle the potential error that io.Closer.Close can return:
This is resolved if you inline/duplicate the pick method, defer func() {if close := resp.Body.Close(); err == nil { err = close } }(), since now there is a direct call to resp.Body.Close(), but the polymorphism and convenience of making a function for this is paramount.
It is also worth noting that defer func(f func() error) { f() }(resp.Body.Close) also fails.
The text was updated successfully, but these errors were encountered:
summary
Similar to #18, when the
http.Response.Body.Close
method is extracted and called,bodyclose
misses the call and incorrectly warns:background
While this example is so simple as to be meaningless, the core problem comes up when trying to handle the potential error that
io.Closer.Close
can return:This is resolved if you inline/duplicate the pick method,
defer func() {if close := resp.Body.Close(); err == nil { err = close } }()
, since now there is a direct call toresp.Body.Close()
, but the polymorphism and convenience of making a function for this is paramount.It is also worth noting that
defer func(f func() error) { f() }(resp.Body.Close)
also fails.The text was updated successfully, but these errors were encountered: