mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
This builds on #1644 and adds automatic per-loop variables that are consistent with go 1.22 behavior. See #1643 for discussion. This is still a draft because the for7 version ends up capturing the per-loop var values when they are +1 relative to what they should be. Maybe somehow the incrementing and conditional code is somehow capturing the within loop variables and incrementing them? not sure how that would work. anyway, need to investigate further before this is ready to go, but pushing it here in case there are other issues or someone might figure out this bug before I do..
19 lines
194 B
Go
19 lines
194 B
Go
package main
|
|
|
|
func main() {
|
|
foos := []func(){}
|
|
|
|
for i := 0; i < 3; i++ {
|
|
i := i
|
|
foos = append(foos, func() { println(i) })
|
|
}
|
|
foos[0]()
|
|
foos[1]()
|
|
foos[2]()
|
|
}
|
|
|
|
// Output:
|
|
// 0
|
|
// 1
|
|
// 2
|