Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.0.1-2020.1.5 / ir / testdata / valueforexpr.go
1 //+build ignore
2
3 package main
4
5 // This file is the input to TestValueForExpr in source_test.go, which
6 // ensures that each expression e immediately following a /*@kind*/(x)
7 // annotation, when passed to Function.ValueForExpr(e), returns a
8 // non-nil Value of the same type as e and of kind 'kind'.
9
10 func f(spilled, unspilled int) {
11         _ = /*@Load*/ (spilled)
12         _ = /*@Parameter*/ (unspilled)
13         _ = /*@nil*/ (1 + 2) // (constant)
14         i := 0
15
16         f := func() (int, int) { return 0, 0 }
17
18         (print( /*@BinOp*/ (i + 1)))
19         _, _ = /*@Call*/ (f())
20         ch := /*@MakeChan*/ (make(chan int))
21         /*@Recv*/ (<-ch)
22         x := /*@Recv*/ (<-ch)
23         _ = x
24         select {
25         case /*@Extract*/ (<-ch):
26         case x := /*@Extract*/ (<-ch):
27                 _ = x
28         }
29         defer /*@Function*/ (func() {
30         })()
31         go /*@Function*/ (func() {
32         })()
33         y := 0
34         if true && /*@BinOp*/ (bool(y > 0)) {
35                 y = 1
36         }
37         _ = /*@Phi*/ (y)
38         map1 := /*@MakeMap*/ (make(map[string]string))
39         _ = map1
40         _ = /*@Slice*/ (make([]int, 0))
41         _ = /*@MakeClosure*/ (func() { print(spilled) })
42
43         sl := []int{}
44         _ = /*@Slice*/ (sl[:0])
45
46         _ = /*@Alloc*/ (new(int))
47         tmp := /*@Alloc*/ (new(int))
48         _ = tmp
49         var iface interface{}
50         _ = /*@TypeAssert*/ (iface.(int))
51         _ = /*@Load*/ (sl[0])
52         _ = /*@IndexAddr*/ (&sl[0])
53         _ = /*@Index*/ ([2]int{}[0])
54         var p *int
55         _ = /*@Load*/ (*p)
56
57         _ = /*@Load*/ (global)
58         /*@Load*/ (global)[""] = ""
59         /*@Global*/ (global) = map[string]string{}
60
61         var local t
62         /*UnOp*/ (local.x) = 1
63
64         // Exercise corner-cases of lvalues vs rvalues.
65         type N *N
66         var n N
67         /*@Load*/ (n) = /*@Load*/ (n)
68         /*@ChangeType*/ (n) = /*@Alloc*/ (&n)
69         /*@Load*/ (n) = /*@Load*/ (*n)
70         /*@Load*/ (n) = /*@Load*/ (**n)
71 }
72
73 func complit() {
74         // Composite literals.
75         // We get different results for
76         // - composite literal as value (e.g. operand to print)
77         // - composite literal initializer for addressable value
78         // - composite literal value assigned to blank var
79
80         // 1. Slices
81         print( /*@Slice*/ ([]int{}))
82         print( /*@Alloc*/ (&[]int{}))
83         print(& /*@Slice*/ ([]int{}))
84
85         sl1 := /*@Slice*/ ([]int{})
86         sl2 := /*@Alloc*/ (&[]int{})
87         sl3 := & /*@Slice*/ ([]int{})
88         _, _, _ = sl1, sl2, sl3
89
90         _ = /*@Slice*/ ([]int{})
91         _ = /*@Alloc*/ (& /*@Slice*/ ([]int{}))
92         _ = & /*@Slice*/ ([]int{})
93
94         // 2. Arrays
95         print( /*@Load*/ ([1]int{}))
96         print( /*@Alloc*/ (&[1]int{}))
97         print(& /*@Alloc*/ ([1]int{}))
98
99         arr1 := /*@Alloc*/ ([1]int{})
100         arr2 := /*@Alloc*/ (&[1]int{})
101         arr3 := & /*@Alloc*/ ([1]int{})
102         _, _, _ = arr1, arr2, arr3
103
104         _ = /*@Load*/ ([1]int{})
105         _ = /*@Alloc*/ (& /*@Alloc*/ ([1]int{}))
106         _ = & /*@Alloc*/ ([1]int{})
107
108         // 3. Maps
109         type M map[int]int
110         print( /*@MakeMap*/ (M{}))
111         print( /*@Alloc*/ (&M{}))
112         print(& /*@MakeMap*/ (M{}))
113
114         m1 := /*@MakeMap*/ (M{})
115         m2 := /*@Alloc*/ (&M{})
116         m3 := & /*@MakeMap*/ (M{})
117         _, _, _ = m1, m2, m3
118
119         _ = /*@MakeMap*/ (M{})
120         _ = /*@Alloc*/ (& /*@MakeMap*/ (M{}))
121         _ = & /*@MakeMap*/ (M{})
122
123         // 4. Structs
124         print( /*@Load*/ (struct{}{}))
125         print( /*@Alloc*/ (&struct{}{}))
126         print(& /*@Alloc*/ (struct{}{}))
127
128         s1 := /*@Alloc*/ (struct{}{})
129         s2 := /*@Alloc*/ (&struct{}{})
130         s3 := & /*@Alloc*/ (struct{}{})
131         _, _, _ = s1, s2, s3
132
133         _ = /*@Load*/ (struct{}{})
134         _ = /*@Alloc*/ (& /*@Alloc*/ (struct{}{}))
135         _ = & /*@Alloc*/ (struct{}{})
136 }
137
138 type t struct{ x int }
139
140 // Ensure we can locate methods of named types.
141 func (t) f(param int) {
142         _ = /*@Parameter*/ (param)
143 }
144
145 // Ensure we can locate init functions.
146 func init() {
147         m := /*@MakeMap*/ (make(map[string]string))
148         _ = m
149 }
150
151 // Ensure we can locate variables in initializer expressions.
152 var global = /*@MakeMap*/ (make(map[string]string))