Debian Codegraph @

src/cmd/compile/internal/loopvar/testdata/range_esc_closure_linedir.go

raw
1 // Copyright 2026 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //line range_esc_closure_linedir.go:5
6 package main
7
8 import "fmt"
9
10 var is []func() int
11
12 func main() {
13 var ints = []int{0, 0, 0}
14 for i := range ints {
15 is = append(is, func() int { return i })
16 }
17
18 for _, f := range is {
19 fmt.Println(f())
20 if f() != 2 {
21 panic("loop variable i: expected shared per-loop, but got distinct per-iteration")
22 }
23 }
24 }