Skip to content

cmd/compile: ++ counts as using a variable, shouldn't #23416

@heschi

Description

@heschi

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:

package main

func main() {
	x := 0
	x++
}

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions