gordonklaus / ineffassign

Detect ineffectual assignments in Go code.
MIT License
394 stars 22 forks source link

Possible false positive #30

Closed alexbilbie closed 5 years ago

alexbilbie commented 5 years ago
package main

type A struct {
    S string
}

func main() {
    aList := []A{
        {S: "Foo"},
        {S: "Bar"},
    }

    var result *A
    for _, i := range aList {
        if i.S == "foobar" {
            result = &i
            break
        }
    }

    if result == nil {
        vsf := A{S: "baz"}
        result = &vsf
    }
}

Reported error:

main.go:23:3: ineffectual assignment to `result` (ineffassign)
alexbilbie commented 5 years ago

Nevermind, I understand why this is being reported - it's ineffectual because the result var isn't actually being used