You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tbh, I'm really puzzled that we could have this bug. I could have sworn we have a regression test for this pattern, but here we are.
Interestingly, if you use the "other version" of this pattern (I prefer your version, but I believe most people use the version below), then yaegi behaves correctly:
Thanks, I'm using a workaround, using a counter to reference array elements.
It seems that when a variable is passed as a parameter to the go routine, if the variable is changed outside by the range operation, the local variable in the go routines get updated, too. Which makes all go routines end up using the same value. Just a wild guess.
var wg sync.WaitGroup
i := 0
for i < len(hits) {
wg.Add(1)
go func(hit string) {
fmt.Println("hit = " + hit)
defer wg.Done()
}(hits[i])
i++
}
wg.Wait()
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
0.14.3
Additional Notes
No response
The text was updated successfully, but these errors were encountered: