gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/tools/go_generics/tests/all_stmts/output.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "sync" 19 ) 20 21 func h(Q) { 22 } 23 24 type s struct { 25 a, b int 26 c []int 27 } 28 29 func g(Q) *s { 30 return &s{} 31 } 32 33 func f() (Q, []int) { 34 // Branch. 35 goto T 36 goto R 37 38 // Labeled. 39 T: 40 _ = Q(0) 41 42 // Empty. 43 R: 44 ; 45 46 // Assignment with definition. 47 a, b, c := Q(1), Q(2), Q(3) 48 _, _, _ = a, b, c 49 50 // Assignment without definition. 51 g(Q(0)).a, g(Q(1)).b, c = int(Q(1)), int(Q(2)), Q(3) 52 _, _, _ = a, b, c 53 54 // Block. 55 { 56 var T Q 57 T = 0 58 _ = T 59 } 60 61 // Declarations. 62 type Type Q 63 const Const Q = 10 64 var g1 func(Q, int, ...Q) (int, Q) 65 var v Q 66 var w = Q(0) 67 { 68 var T struct { 69 f []Q 70 } 71 _ = T 72 } 73 74 // Defer. 75 defer g1(Q(0), 1) 76 77 // Expression. 78 h(v + w + Q(1)) 79 80 // For statements. 81 for i := Q(0); i < Q(10); i++ { 82 var T func(int) Q 83 v := T(0) 84 _ = v 85 } 86 87 for { 88 var T func(int) Q 89 v := T(0) 90 _ = v 91 } 92 93 // Go. 94 go g1(Q(0), 1) 95 96 // If statements. 97 if a != Q(1) { 98 var T func(int) Q 99 v := T(0) 100 _ = v 101 } 102 103 if a := Q(0); a != Q(1) { 104 var T func(int) Q 105 v := T(0) 106 _ = v 107 } 108 109 if a := Q(0); a != Q(1) { 110 var T func(int) Q 111 v := T(0) 112 _ = v 113 } else if b := Q(0); b != Q(1) { 114 var T func(int) Q 115 v := T(0) 116 _ = v 117 } else if T := Q(0); T != 1 { 118 T++ 119 _ = T 120 } else { 121 T-- 122 _ = T 123 } 124 125 if a := Q(0); a != Q(1) { 126 var T func(int) Q 127 v := T(0) 128 _ = v 129 } else { 130 var T func(int) Q 131 v := T(0) 132 _ = v 133 } 134 135 // Inc/Dec statements. 136 (*(*Q)(nil))++ 137 (*(*Q)(nil))-- 138 139 // Range statements. 140 for g(Q(0)).a, g(Q(1)).b = range g(Q(10)).c { 141 var d Q 142 _ = d 143 } 144 145 for T, b := range g(Q(10)).c { 146 _ = T 147 _ = b 148 } 149 150 // Select statement. 151 { 152 var fch func(Q) chan int 153 154 select { 155 case <-fch(Q(30)): 156 var T Q 157 T = 0 158 _ = T 159 default: 160 var T Q 161 T = 0 162 _ = T 163 case T := <-fch(Q(30)): 164 T = 0 165 _ = T 166 case g(Q(0)).a = <-fch(Q(30)): 167 var T Q 168 T = 0 169 _ = T 170 case fch(Q(30)) <- int(Q(0)): 171 var T Q 172 T = 0 173 _ = T 174 } 175 } 176 177 // Send statements. 178 { 179 var ch chan Q 180 var fch func(Q) chan int 181 182 ch <- Q(0) 183 fch(Q(1)) <- g(Q(10)).a 184 } 185 186 // Switch statements. 187 { 188 var a Q 189 var b int 190 switch { 191 case a == Q(0): 192 var T Q 193 T = 0 194 _ = T 195 case a < Q(0), b < g(Q(10)).a: 196 var T Q 197 T = 0 198 _ = T 199 default: 200 var T Q 201 T = 0 202 _ = T 203 } 204 } 205 206 switch Q(g(Q(10)).a) { 207 case Q(0): 208 var T Q 209 T = 0 210 _ = T 211 case Q(1), Q(g(Q(10)).a): 212 var T Q 213 T = 0 214 _ = T 215 default: 216 var T Q 217 T = 0 218 _ = T 219 } 220 221 switch b := g(Q(10)); Q(b.a) + Q(10) { 222 case Q(0): 223 var T Q 224 T = 0 225 _ = T 226 case Q(1), Q(g(Q(10)).a): 227 var T Q 228 T = 0 229 _ = T 230 default: 231 var T Q 232 T = 0 233 _ = T 234 } 235 236 // Type switch statements. 237 { 238 var interfaceFunc func(Q) any 239 240 switch interfaceFunc(Q(0)).(type) { 241 case *Q, Q, int: 242 var T Q 243 T = 0 244 _ = T 245 case sync.Mutex, **Q: 246 var T Q 247 T = 0 248 _ = T 249 default: 250 var T Q 251 T = 0 252 _ = T 253 } 254 255 switch x := interfaceFunc(Q(0)).(type) { 256 case *Q, Q, int: 257 var T Q 258 T = 0 259 _ = T 260 _ = x 261 case sync.Mutex, **Q: 262 var T Q 263 T = 0 264 _ = T 265 default: 266 var T Q 267 T = 0 268 _ = T 269 } 270 271 switch t := Q(0); x := interfaceFunc(Q(0) + t).(type) { 272 case *Q, Q, int: 273 var T Q 274 T = 0 275 _ = T 276 _ = x 277 case sync.Mutex, **Q: 278 var T Q 279 T = 0 280 _ = T 281 default: 282 var T Q 283 T = 0 284 _ = T 285 } 286 } 287 288 // Return statement. 289 return Q(10), g(Q(11)).c 290 }