-
Notifications
You must be signed in to change notification settings - Fork 41
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
Allow defer statements after error checking #31
Comments
Hi, thanks for the report! Seems reasonable, I'll add this to the TODO list! |
It might be beneficial to allow methods other than Close() to be used in defer. Many libraries use names like Free(), Release(), Shutdown(), etc. |
This was reworked in #133 in June, it's now allowed to defer any call as long as it's used two statements above. There are a bunch of examples with allowed values in the test: wsl/testdata/src/default_config/defer.go Lines 6 to 35 in 7edb3ef
|
It is good practice to defer a close statement for a HTTP response body after the error check as discussed in https://stackoverflow.com/questions/33238518/what-could-happen-if-i-dont-close-response-body-in-golang#33238755
In my opinion, this defer statement should logically be part of the block where the body originates so I think we should allow the following:
instead of enforcing the following:
The text was updated successfully, but these errors were encountered: