mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.69k stars 269 forks source link

False positive datarace detection in Go 1.22 #975

Closed EldarKurbanov closed 1 month ago

EldarKurbanov commented 4 months ago

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:

  1. 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()

}


2. Enable all rules in config:
```toml
enableAllRules = true
  1. 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):

dominiquelefevre commented 1 month ago

https://github.com/mgechev/revive/pull/993

chavacava commented 1 month ago

closed by #993