Skip to content
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
Open

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

gopherbot opened this issue Jun 16, 2014 · 2 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis)
Milestone

Comments

@gopherbot
Copy link

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
Copy link
Contributor

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
Copy link
Member

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.

@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 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
@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 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
@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis)
Projects
None yet
Development

No branches or pull requests

5 participants