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

Question: would it be relevant to warn about unused returned values #21976

Closed
fpeterschmitt opened this issue Sep 22, 2017 · 1 comment
Closed

Comments

@fpeterschmitt
Copy link

Hello,

This is not a bug report, only a question about how go compiles and warns about unused values from function calls (see the play paste for the example).

While go has nothing to do with the programmer not checking for returned values, i found myself easily forgetting to do so, leading to a panic because of a prior error.

What about warning about unused returned values?

What version of Go are you using (go version)?

go1.9 linux/amd64

What did you do?

https://play.golang.org/p/pLQ9_3nGA9

What did you expect to see?

When running go run main.go, or any build step, i would like the compiler to warn me about a unused return value from the return_error() function call.

What did you see instead?

The build silently pass.

@dominikh
Copy link
Member

The compiler doesn't emit warnings, by design. And it can't emit an error for this kind of issue (definitely not in Go 1, and probably not in Go 2, either). There is the vet tool, but this kind of warning would be very noisy in a lot of cases.

You can use a 3rd party tool, such as errcheck, for this, though. It checks for returned error values that are ignored.

@golang golang locked and limited conversation to collaborators Sep 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants