Open
Description
Proposal Details
Reassignment of variables of type sync.WaitGroup
is likely to cause bugs due to the potential to overwrite a WaitGroup with a non-zero counter value with a WaitGroup that has a zero counter. I can't think of any scenarios whereby reassigning a variable of type sync.WaitGroup
would be required or useful. The waitgroup analysis pass should be extended to report reassignments of sync.WaitGroup
variables.
Example
package main
import (
"sync"
)
type Object struct {
wg sync.WaitGroup
}
var wg0 sync.WaitGroup
func main() {
var wg1 sync.WaitGroup // ok
wg2 := sync.WaitGroup{} // ok
var wg3 sync.WaitGroup = sync.WaitGroup{} // ok
obj := Object{
wg: sync.WaitGroup{}, // ok
}
wg0 = sync.WaitGroup{} // want: variable of type sync.WaitGroup reassigned
wg1 = sync.WaitGroup{} // want: variable of type sync.WaitGroup reassigned
obj.wg = sync.WaitGroup{} // want: variable of type sync.WaitGroup reassigned
wg0.Wait()
wg1.Wait()
wg2.Wait()
wg3.Wait()
}
Should this proposal be approved, I'd like to contribute the aforementioned changes.