-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/compile: ++ counts as using a variable, shouldn't #23416
Comments
Working as designed, because |
One error that can be given is that the last assigned value is unused. For example, when one does It is a different error, but perhaps one that would be easier to integrate into vet and other static analysis tools. |
That's #6072, which I personally feel is a weaker case than this. I suppose if the best way to implement this check is an SSA analysis then both really are the same. |
FWIW, the github.com/gordonklaus/ineffassign analyzer reports this mistake, and it doesn't use SSA. (It constructs its own control-flow graph similar to ctrlflow.)
|
What version of Go are you using (
go version
)?1.9.2, as seen on the playground.
Does this issue reproduce with the latest release?
Yes.
What did you do?
https://play.golang.org/p/2RuYMrSLjt3:
What did you expect to see?
A compiler error saying that x is unused. For the purposes of removing useless code, ++ isn't any more of a reason to have a variable than the initial assignment. += behaves the same way.
What did you see instead?
Nothing, apparently because x++ counts as using the variable. go vet also seems content.
It's hard to believe this has never been reported before, but the closest bug Alan and I could find is https://golang.org/issue/10989, which is rather different.
I don't know if it's worth catching this as a compile error, but it ought to at least be reported by vet?
The text was updated successfully, but these errors were encountered: