traefik / yaegi

Yaegi is Another Elegant Go Interpreter

Home Page:https://pkg.go.dev/github.com/traefik/yaegi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

incorrect output when closure is set in a loop

mvertes opened this issue · comments

The following program sample.go triggers an unexpected result

package main

func main() {
	var fns []func()
	for _, v := range []int{1, 2, 3} {
		x := v*100 + v
		fns = append(fns, func() { println(x) })
	}
	for _, fn := range fns {
		fn()
	}
}

Expected result

$ go run ./sample.go
101
202
303

Got

$ yaegi ./sample.go
303
303
303

Yaegi Version

v0.15.1

Additional Notes

The same issue as in gnolang/gno#1135