Skip to content

SA4006: detect unused writes with += #1329

Open
@cespare

Description

$ staticcheck -debug.version
staticcheck 2022.1.3 (v0.3.3)

Compiled with Go version: go1.18.4
Main module:
        honnef.co/go/[email protected] (sum: h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=)
Dependencies:
        github.com/BurntSushi/[email protected] (sum: h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=)
        golang.org/x/exp/[email protected] (sum: h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=)
        golang.org/x/[email protected] (sum: h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=)
        golang.org/x/[email protected] (sum: h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=)
        golang.org/x/[email protected] (sum: h1:OKYpQQVE3DKSc3r3zHVzq46vq5YH7x8xpR3/k9ixmUg=)

Go version is 1.19.2 linux/amd64.

Example program:

package main

func main() {
	dir := "a"
	dir += "/b"
}

Staticcheck doesn't complain about that. But if I tweak it to

package main

func main() {
	dir := "a"
	dir = dir + "/b"
}

Then I get

x/x.go:5:2: this value of dir is never used (SA4006)

Could SA4006 better detect this case with +=?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions