gordonklaus / ineffassign

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

Uncaught ineffective assignment #15

Closed benma closed 7 years ago

benma commented 7 years ago
package main

import "fmt"

func main() {
    var i int
    i = 3
    i = 5
    fmt.Println(i)
}

$ ineffassign main.go does not produce any results. It should catch that the i = 3 assignment was ineffective (its value was never used).

I created the issue because I discovered an unchecked error in my code because of this pattern, i.e.:

err := someCall()
err = anotherCall()
if err != nil { ... }
gordonklaus commented 7 years ago

Thanks for pointing this out! I'll work up a fix.

benma commented 7 years ago

Excellent, thank you!