Skip to content

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

Description

@gopherbot

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions