package main
+var never bool
+
func main() {
{
type X struct {
{
var g func() int
- for i := range [2]int{} {
+ var i int
+ for i = range [2]int{} {
if i == 0 {
g = func() int {
- return i // test that we capture by ref here, i is mutated on every interation
+ return i // test that we capture by ref here, i is mutated on every interaction
}
}
}
q++
g = func() int {
return q // test that we capture by ref here
- // q++ must on a different decldepth than q declaration
+ // q++ must on a different decldepth than q declaration
}
}
if g() != 2 {
}()] = range [2]int{} {
g = func() int {
return q // test that we capture by ref here
- // q++ must on a different decldepth than q declaration
+ // q++ must on a different decldepth than q declaration
}
}
if g() != 2 {
panic("g() != 2")
}
}
+
+ {
+ var g func() int
+ q := 0
+ q, g = 1, func() int { return q }
+ if never {
+ g = func() int { return 2 }
+ }
+ if g() != 1 {
+ panic("g() != 1")
+ }
+ }
}