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

proposal: add vet check for python style map sums #24391

Closed
frioux opened this issue Mar 14, 2018 · 2 comments
Closed

proposal: add vet check for python style map sums #24391

frioux opened this issue Mar 14, 2018 · 2 comments

Comments

@frioux
Copy link

frioux commented Mar 14, 2018

Please answer these questions before submitting your issue. Thanks!

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

1.10

Does this issue reproduce with the latest release?

Yes

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

GOBIN=""
GOCACHE="/home/frew/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/frew/go"
GORACE=""
GOROOT="/home/frew/go"
GOTMPDIR=""
GOTOOLDIR="/home/frew/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/run/shm/go-build797590454=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/ZU-Ys77Q766

Basically, I have run into many variations of:

			if _, ok := found[x]; ok {
				found[x] += y
			} else {
				found[x] = y
			}

and even surprised some people who have been writing Go for years, when pointing out that thanks to zero values the above is totally superfluous, and that the following is totally sufficient. (Or at least I can't think of a type where it is not.)

			found[x] += y

Note that I think = 1 and ++ should be detected, but presumably as a special case, unless ++ desugars to += 1.

What did you expect to see?

A warning from go vet that the pattern should be corrected.

What did you see instead?

Nothing

@gopherbot gopherbot added this to the Proposal milestone Mar 14, 2018
@ALTree ALTree changed the title Proposal: detect python style map sums proposal: add vet check for python style map sums Mar 14, 2018
@josharian
Copy link
Contributor

This probably belongs in a style checker like lint, or something by @dominikh, because vet is focused solely on correctness. While superfluous, the code will function correctly. Given that, I’m going to close this issue; thanks for floating the idea.

@dominikh
Copy link
Member

It may fit into my gosimple; please file an issue at https://github.com/dominikh/go-tools/issues so that I'll remember :)

@golang golang locked and limited conversation to collaborators Mar 14, 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

4 participants