Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / cmd / guru / testdata / src / describe / main.go
1 package describe // @describe pkgdecl "describe"
2
3 // Tests of 'describe' query.
4 // See go.tools/guru/guru_test.go for explanation.
5 // See describe.golden for expected query results.
6
7 // TODO(adonovan): more coverage of the (extensive) logic.
8
9 import (
10         "lib"
11         "nosuchpkg"            // @describe badimport1 "nosuchpkg"
12         nosuchpkg2 "nosuchpkg" // @describe badimport2 "nosuchpkg2"
13         _ "unsafe"             // @describe unsafe "unsafe"
14 )
15
16 var _ nosuchpkg.T
17 var _ nosuchpkg2.T
18
19 type cake float64 // @describe type-ref-builtin "float64"
20
21 const c = iota // @describe const-ref-iota "iota"
22
23 const pi = 3.141     // @describe const-def-pi "pi"
24 const pie = cake(pi) // @describe const-def-pie "pie"
25 const _ = pi         // @describe const-ref-pi "pi"
26
27 var global = new(string) // NB: ssa.Global is indirect, i.e. **string
28
29 func main() { // @describe func-def-main "main"
30         // func objects
31         _ = main      // @describe func-ref-main "main"
32         _ = (*C).f    // @describe func-ref-*C.f "..C..f"
33         _ = D.f       // @describe func-ref-D.f "D.f"
34         _ = I.f       // @describe func-ref-I.f "I.f"
35         var d D       // @describe type-D "D"
36         var i I       // @describe type-I "I"
37         _ = d.f       // @describe func-ref-d.f "d.f"
38         _ = i.f       // @describe func-ref-i.f "i.f"
39         var slice []D // @describe slice-of-D "slice"
40
41         var dptr *D // @describe ptr-with-nonptr-methods "dptr"
42         _ = dptr
43
44         // var objects
45         anon := func() {
46                 _ = d // @describe ref-lexical-d "d"
47         }
48         _ = anon   // @describe ref-anon "anon"
49         _ = global // @describe ref-global "global"
50
51         // SSA affords some local flow sensitivity.
52         var a, b int
53         var x = &a // @describe var-def-x-1 "x"
54         _ = x      // @describe var-ref-x-1 "x"
55         x = &b     // @describe var-def-x-2 "x"
56         _ = x      // @describe var-ref-x-2 "x"
57
58         i = new(C) // @describe var-ref-i-C "i"
59         if i != nil {
60                 i = D{} // @describe var-ref-i-D "i"
61         }
62         print(i) // @describe var-ref-i "\\bi\\b"
63
64         // const objects
65         const localpi = 3.141     // @describe const-local-pi "localpi"
66         const localpie = cake(pi) // @describe const-local-pie "localpie"
67         const _ = localpi         // @describe const-ref-localpi "localpi"
68
69         // type objects
70         type T int      // @describe type-def-T "T"
71         var three T = 3 // @describe type-ref-T "T"
72         _ = three
73
74         print(1 + 2*3)        // @describe const-expr " 2.3"
75         print(real(1+2i) - 3) // @describe const-expr2 "real.*3"
76
77         m := map[string]*int{"a": &a}
78         mapval, _ := m["a"] // @describe map-lookup,ok "m..a.."
79         _ = mapval          // @describe mapval "mapval"
80         _ = m               // @describe m "m"
81
82         defer main() // @describe defer-stmt "defer"
83         go main()    // @describe go-stmt "go"
84
85         panic(3) // @describe builtin-ref-panic "panic"
86
87         var a2 int // @describe var-decl-stmt "var a2 int"
88         _ = a2
89         var _ int // @describe var-decl-stmt2 "var _ int"
90         var _ int // @describe var-def-blank "_"
91
92         var _ lib.Outer // @describe lib-outer "Outer"
93
94         var mmm map[C]D // @describe var-map-of-C-D "mmm"
95
96         d := newD().ThirdField // @describe field-access "ThirdField"
97
98         astCopy := ast
99         unknown() // @describe call-unknown "\\("
100 }
101
102 type I interface { // @describe def-iface-I "I"
103         f() // @describe def-imethod-I.f "f"
104 }
105
106 type C int
107 type D struct {
108         Field        int
109         AnotherField string
110         ThirdField   C
111 }
112
113 func (c *C) f() {}
114 func (d D) f()  {}
115
116 func newD() D { return D{} }