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: declared but not used #23887

Closed
sabey opened this issue Feb 17, 2018 · 4 comments
Closed

cmd/vet: declared but not used #23887

sabey opened this issue Feb 17, 2018 · 4 comments

Comments

@sabey
Copy link

sabey commented Feb 17, 2018

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

go version go1.10 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

amd64

What did you do?

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

package main

type Server struct {
	Counter func()
}

func main() {
	counter := 0
	server := &Server{
		Counter: func() {
			counter = 1
		},
	}
	for i := 0; i < 100; i++ {
		server.Counter()
	}
}

go vet // fails, didn't fail pre go1.10
go run main.go // no problem

if you change counter = 1 to counter++ or counter = counter + 1 there is no error

What did you expect to see?

no error

What did you see instead?

./main.go:8:2: counter declared but not used
vet: typecheck failures

@dgryski
Copy link
Contributor

dgryski commented Feb 17, 2018

Assignment-only expressions don't count as "use" -- you need a read. Both ++ and counter + 1 are reads.

@ALTree
Copy link
Member

ALTree commented Feb 17, 2018

The fact that gc should issue an error (and it doesn't) is #3059.

Also this is not vet reporting an issue, but go/types correctly raising an error during typechecking. I guess vet was changed during the 1.10 cycle to print typechecking errors instead of ignoring them.

@ALTree
Copy link
Member

ALTree commented Feb 17, 2018

Found the discussion, is at #21287 (cmd/vet: decide how to handle type checking failure). Final decision was:

So the decision here is "go vet" will be fixed so that it can always typecheck, and then failure to typecheck will be a fatal error.

Explicitly mentioning this change in the 1.10 release notes would have been nice, but I don't see anything in https://golang.org/doc/go1.10#vet

Anyway, vet side, this is working as expected. We still have the gc issue I linked above.

@ianlancetaylor
Copy link
Contributor

I don't think there is anything to do here. The vet error is correct, even if the compiler proper doesn't catch it. Closing.

@golang golang locked and limited conversation to collaborators Feb 17, 2019
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

5 participants