Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/vet: No warning for some statements with no effect #8220
What does 'go version' print? go version go1.2 linux/amd64 What steps reproduce the problem? If possible, include a link to a program on play.golang.org. In this toy example (which represents a pattern of bugs that crops up fairly frequently for our team), I have forgotten to make err a named return value in my deferred function. The intent was to propagate any error that occurred during execution of the deffered function, but since I forgot to make err a named return value, the error gets dropped. http://play.golang.org/p/MD8tetH4ZI What happened? The program compiled and ran without error. What should have happened instead? The compiler should have errored that the statement "err = e" had no effect. Bonus points if it suggested that I might have meant to use a named return value.
So what's the pattern? A deferred anon function assigns to an enclosing local that is never used within the deferred function, and is not a named return parameter? This isn't necessarily a bug, as it's very hard to prove that the store is dead. Consider: http://play.golang.org/p/5p_IUn56qA defer/panic code is so rare (and so inherently complex) that I doubt it would be worth looking for this pattern in vet.