revive
revive copied to clipboard
False positive datarace detection in Go 1.22
Describe the bug I see this linter warning in my project which uses Go 1.22 in go.mod: datarace: datarace: range value i is captured (by-reference) in goroutine (revive)
To Reproduce Steps to reproduce the behavior:
- Write this code:
package test
import (
"log"
"sync"
"testing"
)
func Test(t *testing.T) {
t.Parallel()
clients := []string{"a", "b", "c", "d", "e"}
wg := sync.WaitGroup{}
const one = 1
for i := range clients {
wg.Add(one)
go func() {
defer wg.Done()
log.Println(clients[i])
}()
}
wg.Wait()
}
- Enable all rules in config:
enableAllRules = true
- Run revive:
revive -config conf.toml .
Expected behavior No warning for Go 1.22
Logs PS C:\Users\Eldar\Projects\test> revive -config conf.toml . a_test.go:23:24: datarace: range value i is captured (by-reference) in goroutine a_test.go:23:24: loop variable i captured by func literal
Desktop (please complete the following information):
- OS: Windows 11 Pro 23H2
- go version go1.22.0 windows/amd64
- Revive version 1.3.7