-
Notifications
You must be signed in to change notification settings - Fork 1
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 negative with defer
#6
Comments
🤔 I will check it 🤔 |
I use another function and print the blocks and instrs func Call18() error {
defer func() {}() // the test passes if you remove defer
err := Do()
if err != nil {
return err
}
err2 := Do2()
if err2 != nil {
return err // want `return a nil value error after check error`
}
return nil
}
the |
Ah! Was scratching my head after enabling this linter (which looks very useful!) and my first attempt to make it trip failing; I also deducted it to be related to defers (initially thought its was named output variables); here was my reproducer, which looks quite similar, except in my case the defer was defined after the checks (so effectively, no defer yet in sight) package main
import "fmt"
func main() {
_ = example()
}
func example() error {
_, err := fmt.Println()
if err != nil {
return err
}
_, err2 := fmt.Println()
if err2 != nil {
return err // which should return err2 after check `err2 != nil`, but return a nil value error
}
defer func() {}()
return nil
} |
The same issue exists in gostaticanalysis/nilerr#19.
The following test fails:
The text was updated successfully, but these errors were encountered: