Avoid a spurious optimisation which forces a variable to be reused instead of redefined for assignment operation. This ensures that a variable defined in a loop is re-allocated, preserving the previous instance when used by a closure for example. Fix #1594
18 lines
216 B
Go
18 lines
216 B
Go
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()
|
|
}
|
|
}
|
|
|
|
// Output:
|
|
// 101
|
|
// 202
|
|
// 303
|