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

cmd/vet: No warning for some statements with no effect #8220

Open
gopherbot opened this Issue Jun 16, 2014 · 2 comments

Comments

Projects
None yet
5 participants
@gopherbot

gopherbot commented Jun 16, 2014

by tmadams@google.com:

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.
@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Jun 16, 2014

Comment 1:

I don't think it is feasible or useful to issue this error in the compiler.
I think it might be possible in the vet tool.

Labels changed: added repo-tools, release-none.

@adonovan

This comment has been minimized.

adonovan commented Dec 6, 2014

Comment 2:

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.

@gopherbot gopherbot added new labels Dec 6, 2014

@bradfitz bradfitz removed the new label Dec 18, 2014

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed the release-none label Apr 10, 2015

@rsc rsc changed the title from cmd/vet: No warning for some statements with no effect to x/tools/cmd/vet: No warning for some statements with no effect Apr 14, 2015

@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015

@rsc rsc removed the repo-tools label Apr 14, 2015

@mvdan mvdan changed the title from x/tools/cmd/vet: No warning for some statements with no effect to cmd/vet: No warning for some statements with no effect May 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment