gordonklaus / ineffassign

Detect ineffectual assignments in Go code.
MIT License
398 stars 23 forks source link

False positive #9

Closed tanji closed 8 years ago

tanji commented 8 years ago

Example from my code:

    for _, server := range servers {
        f := false
        if server.State == stateUnconn || server.State == stateFailed {
            if f == false {
                f = true
                vy++
            }

Error message: f assigned and not used (ineffassign)

f has already been assigned in the outer loop so error should not happen when f is set to true.

gordonklaus commented 8 years ago

f is assigned (f = true) and then not used (unless it is used on a line beyond what you've posted). Maybe you meant to declare f outside the loop? Or meant to write for server.State == ... instead of if server.State == ...?

tanji commented 8 years ago

You are right, f should have been declared outside the loop... Sorry for missing that obvious one :(