mirror of
https://github.com/traefik/yaegi.git
synced 2026-06-01 18:37:56 +00:00
The first change forces a variable definition to reallocate a new memory slot to avoid corrupting a previously defined one in a loop block. The second change ensures that the frame clone operations obtains a copy of the original data slice, to preserve the original context set in a loop. Fixes #1035.
19 lines
203 B
Go
19 lines
203 B
Go
package main
|
|
|
|
func main() {
|
|
foos := []func(){}
|
|
|
|
for i := 0; i < 3; i++ {
|
|
a := i
|
|
foos = append(foos, func() { println(i, a) })
|
|
}
|
|
foos[0]()
|
|
foos[1]()
|
|
foos[2]()
|
|
}
|
|
|
|
// Output:
|
|
// 3 0
|
|
// 3 1
|
|
// 3 2
|