gordonklaus / ineffassign

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

False positive in the-eye-team/reddit-dl #45

Closed nektro closed 4 years ago

nektro commented 4 years ago

I noticed the usage here https://goreportcard.com/report/github.com/The-Eye-Team/reddit-dl#ineffassign. In it, I have code very similar to the following..

l := true

if complicatedCondition() {
    l = false
}
if anotherComplicatedCondition() {
    l = false
}
if l {
    // do some code that handles the default case
}

and ineffassign is labeling the l = false lines as ineffectual assigns. I believe this to be a bug. Conversation welcome :)

gordonklaus commented 4 years ago

I took a look and found something similar to the following as well:

if condition() {
    l = false
} else {
    l = false
}

which amounts to an unconditional assignment to l, making all the preceding assignments ineffectual. I suppose the bug is that one of these two assignments shouldn't exist?

nektro commented 4 years ago

Good point, sorry for the bug.