github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/oracle/testdata/src/main/freevars.go (about) 1 package main 2 3 // Tests of 'freevars' query. 4 // See go.tools/oracle/oracle_test.go for explanation. 5 // See freevars.golden for expected query results. 6 7 // TODO(adonovan): it's hard to test this query in a single line of gofmt'd code. 8 9 type T struct { 10 a, b int 11 } 12 13 type S struct { 14 x int 15 t T 16 } 17 18 func f(int) {} 19 20 func main() { 21 type C int 22 x := 1 23 const exp = 6 24 if y := 2; x+y+int(C(3)) != exp { // @freevars fv1 "if.*{" 25 panic("expected 6") 26 } 27 28 var s S 29 30 for x, y := range "foo" { 31 println(s.x + s.t.a + s.t.b + x + int(y)) // @freevars fv2 "print.*y." 32 } 33 34 f(x) // @freevars fv3 "f.x." 35 36 // TODO(adonovan): enable when go/types supports labels. 37 loop: // #@freevars fv-def-label "loop:" 38 for { 39 break loop // #@freevars fv-ref-label "break loop" 40 } 41 }