gordonklaus / ineffassign

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

Uncaught #24

Closed mattdee123 closed 5 years ago

mattdee123 commented 6 years ago
package foo

func foo() {
    x := 1
    x = 2
    return &x
}

The initial assignment is ineffective, but isn't caught here, due to the fact that x escapes.

gordonklaus commented 5 years ago

I'm going to say fixing this is beyond the scope of this tool. A variable that escapes could end up being used at any point in the program (even after to the apparent ineffective assignment above, if there was synchronization with another goroutine where the use occurred), which only a complete pointer analysis could determine.