dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.15k stars 373 forks source link

SA4006 false positive #1404

Closed AlexanderYastrebov closed 1 year ago

AlexanderYastrebov commented 1 year ago
$ staticcheck -debug.version
staticcheck 2023.1.3 (v0.4.3)

Compiled with Go version: go1.20.4
Main module:
        honnef.co/go/tools@v0.4.3 (sum: h1:o/n5/K5gXqk8Gozvs2cnL0F2S1/g1vcGCAx2vETjITw=)
Dependencies:
        github.com/BurntSushi/toml@v1.2.1 (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=)
        golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=)
        golang.org/x/mod@v0.7.0 (sum: h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=)
        golang.org/x/sys@v0.3.0 (sum: h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=)
        golang.org/x/tools@v0.4.1-0.20221208213631-3f74d914ae6d (sum: h1:9ZNWAi4CYhNv60mXGgAncgq7SGc5qa7C8VZV8Tg7Ggs=)
// You can edit this code!
// Click here and start typing.
package main

func main() {
    keys := []string{"foo", "bar", "foo"}

    m := make(map[string]string)
    for _, k := range keys {
        p, ok := m[k]
        if !ok {
            p = "value of " + k
            m[k] = p
        } else {
            continue
        }
        println(p)
    }
}

Playground link: https://go.dev/play/p/QaA_67_EhZ-

$ staticcheck main.go 
main.go:10:3: this value of p is never used (SA4006)
dominikh commented 1 year ago

Not a false positive.