Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive datarace detection in Go 1.22 #975

Closed
EldarKurbanov opened this issue Mar 4, 2024 · 2 comments
Closed

False positive datarace detection in Go 1.22 #975

EldarKurbanov opened this issue Mar 4, 2024 · 2 comments

Comments

@EldarKurbanov
Copy link

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()
}
  1. Enable all rules in config:
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):

  • OS: Windows 11 Pro 23H2
  • go version go1.22.0 windows/amd64
  • Revive version 1.3.7
@dominiquelefevre
Copy link
Contributor

dominiquelefevre commented May 28, 2024

#993

@chavacava
Copy link
Collaborator

closed by #993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants