-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: false positive of self-assignment #54840
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
Comments
This comment was marked as outdated.
This comment was marked as outdated.
No, this is a false positive. The thing that looks like a self-assignment modifies |
I do not find the example given in the issue all that compelling.
The root cause is that analysisutils.HasSideEffect is applied the lhs and rhs independenly by the I think we do not want vet warning in this case. |
My example was minimum reproducible code.. Alternative implementation for my case would be if _, found := m["s"]; !found {
m["s"] = nil
} |
Right. I just wanted an example where "if map content exists keep it, if the key doesn't exist, use [zero value]" is clearly the desired operation. This made being a "false positive" more obvious (at least to me). |
Change https://go.dev/cl/438796 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/TBs0FGA9Ry8
What did you expect to see?
nothing
What did you see instead?
./main.go:5:2: self-assignment of m["s"] to m["s"]
I thought this is supposed to be fixed. Looks similar to #22174
The text was updated successfully, but these errors were encountered: