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
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.
The text was updated successfully, but these errors were encountered:
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.
rsc
changed the title
cmd/vet: No warning for some statements with no effect
x/tools/cmd/vet: No warning for some statements with no effect
Apr 14, 2015
mvdan
changed the title
x/tools/cmd/vet: No warning for some statements with no effect
cmd/vet: No warning for some statements with no effect
May 31, 2018
by tmadams@google.com:
The text was updated successfully, but these errors were encountered: