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 / go / pointer / testdata / flow.go
1 // +build ignore
2
3 package main
4
5 // Demonstration of directionality of flow edges.
6
7 func f1() {}
8 func f2() {}
9
10 var somepred bool
11
12 // Tracking functions.
13 func flow1() {
14         s := f1
15         p := f2
16         q := p
17         r := q
18         if somepred {
19                 r = s
20         }
21         print(s) // @pointsto main.f1
22         print(p) // @pointsto main.f2
23         print(q) // @pointsto main.f2
24         print(r) // @pointsto main.f1 | main.f2
25 }
26
27 // Tracking concrete types in interfaces.
28 func flow2() {
29         var s interface{} = 1
30         var p interface{} = "foo"
31         q := p
32         r := q
33         if somepred {
34                 r = s
35         }
36         print(s) // @types int
37         print(p) // @types string
38         print(q) // @types string
39         print(r) // @types int | string
40 }
41
42 var g1, g2 int
43
44 // Tracking addresses of globals.
45 func flow3() {
46         s := &g1
47         p := &g2
48         q := p
49         r := q
50         if somepred {
51                 r = s
52         }
53         print(s) // @pointsto main.g1
54         print(p) // @pointsto main.g2
55         print(q) // @pointsto main.g2
56         print(r) // @pointsto main.g2 | main.g1
57 }
58
59 func main() {
60         flow1()
61         flow2()
62         flow3()
63 }