Vs code reports loop variable being captured by func literal with go1.22 #3381
-
I have go1.22 installed and as far as I can see, there are no reports from vet, when I run it manually. But vs code itself still reports a warning for a loop variable being captured by func literal (loopclosure). Is it something I should do on my end in settings or is it a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
package main
import (
"fmt"
"sync"
)
const num = 10
func main() {
var wg sync.WaitGroup
wg.Add(num)
for i := range num {
go func() {
defer wg.Done()
fmt.Println(i)
}()
}
wg.Wait()
} Example to reproduce. |
Beta Was this translation helpful? Give feedback.
-
I noticed that this behaviour changes as soon as I remove goroutine: |
Beta Was this translation helpful? Give feedback.
-
Probably because of this. |
Beta Was this translation helpful? Give feedback.
Probably because of this.
golang/go#66876