Russ Cox | d2cc988 | 2012-02-16 23:50:37 -0500 | [diff] [blame] | 1 | // errorcheck |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 2 | |
Emmanuel Odeke | 53fd522 | 2016-04-10 14:32:26 -0700 | [diff] [blame] | 3 | // Copyright 2011 The Go Authors. All rights reserved. |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file. |
| 6 | |
Rob Pike | 83976e3 | 2012-02-19 14:28:53 +1100 | [diff] [blame] | 7 | // Verify goto semantics. |
| 8 | // Does not compile. |
| 9 | // |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 10 | // Each test is in a separate function just so that if the |
| 11 | // compiler stops processing after one error, we don't |
| 12 | // lose other ones. |
| 13 | |
| 14 | package main |
| 15 | |
| 16 | var ( |
| 17 | i, n int |
| 18 | x []int |
| 19 | c chan int |
| 20 | m map[int]int |
| 21 | s string |
| 22 | ) |
| 23 | |
| 24 | // goto after declaration okay |
| 25 | func _() { |
| 26 | x := 1 |
| 27 | goto L |
| 28 | L: |
| 29 | _ = x |
| 30 | } |
| 31 | |
| 32 | // goto before declaration okay |
| 33 | func _() { |
| 34 | goto L |
| 35 | L: |
| 36 | x := 1 |
| 37 | _ = x |
| 38 | } |
| 39 | |
| 40 | // goto across declaration not okay |
| 41 | func _() { |
Ian Lance Taylor | f1aefc0 | 2011-09-20 14:45:54 -0700 | [diff] [blame] | 42 | goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 43 | x := 1 // GCCGO_ERROR "defined here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 44 | _ = x |
| 45 | L: |
| 46 | } |
| 47 | |
| 48 | // goto across declaration in inner scope okay |
| 49 | func _() { |
| 50 | goto L |
| 51 | { |
| 52 | x := 1 |
| 53 | _ = x |
| 54 | } |
| 55 | L: |
| 56 | } |
| 57 | |
| 58 | // goto across declaration after inner scope not okay |
| 59 | func _() { |
Ian Lance Taylor | f1aefc0 | 2011-09-20 14:45:54 -0700 | [diff] [blame] | 60 | goto L // ERROR "goto L jumps over declaration of x at LINE+5|goto jumps over declaration" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 61 | { |
| 62 | x := 1 |
| 63 | _ = x |
| 64 | } |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 65 | x := 1 // GCCGO_ERROR "defined here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 66 | _ = x |
| 67 | L: |
| 68 | } |
| 69 | |
| 70 | // goto across declaration in reverse okay |
| 71 | func _() { |
| 72 | L: |
| 73 | x := 1 |
| 74 | _ = x |
| 75 | goto L |
| 76 | } |
| 77 | |
| 78 | // error shows first offending variable |
| 79 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 80 | goto L // ERROR "goto L jumps over declaration of y at LINE+3|goto jumps over declaration" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 81 | x := 1 // GCCGO_ERROR "defined here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 82 | _ = x |
| 83 | y := 1 |
| 84 | _ = y |
| 85 | L: |
| 86 | } |
| 87 | |
| 88 | // goto not okay even if code path is dead |
| 89 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 90 | goto L // ERROR "goto L jumps over declaration of y at LINE+3|goto jumps over declaration" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 91 | x := 1 // GCCGO_ERROR "defined here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 92 | _ = x |
| 93 | y := 1 |
| 94 | _ = y |
| 95 | return |
| 96 | L: |
| 97 | } |
| 98 | |
| 99 | // goto into outer block okay |
| 100 | func _() { |
| 101 | { |
| 102 | goto L |
| 103 | } |
| 104 | L: |
| 105 | } |
| 106 | |
| 107 | // goto backward into outer block okay |
| 108 | func _() { |
| 109 | L: |
| 110 | { |
| 111 | goto L |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // goto into inner block not okay |
| 116 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 117 | goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 118 | { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 119 | L: |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // goto backward into inner block still not okay |
| 124 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 125 | { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 126 | L: |
| 127 | } |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 128 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | // error shows first (outermost) offending block |
| 132 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 133 | goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 134 | { |
| 135 | { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 136 | { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 137 | L: |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // error prefers block diagnostic over declaration diagnostic |
| 144 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 145 | goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 146 | x := 1 |
| 147 | _ = x |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 148 | { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 149 | L: |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // many kinds of blocks, all invalid to jump into or among, |
| 154 | // but valid to jump out of |
| 155 | |
| 156 | // if |
| 157 | |
| 158 | func _() { |
| 159 | L: |
| 160 | if true { |
| 161 | goto L |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | func _() { |
| 166 | L: |
| 167 | if true { |
| 168 | goto L |
| 169 | } else { |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | func _() { |
| 174 | L: |
| 175 | if false { |
| 176 | } else { |
| 177 | goto L |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 182 | goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 183 | if true { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 184 | L: |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 189 | goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 190 | if true { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 191 | L: |
| 192 | } else { |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 197 | goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 198 | if true { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 199 | } else { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 200 | L: |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 205 | if false { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 206 | L: |
| 207 | } else { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 208 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | func _() { |
| 213 | if true { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 214 | goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 215 | } else { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 216 | L: |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | func _() { |
| 221 | if true { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 222 | goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 223 | } else if false { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 224 | L: |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | func _() { |
| 229 | if true { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 230 | goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block" |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 231 | } else if false { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 232 | L: |
| 233 | } else { |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | func _() { |
| 238 | // This one is tricky. There is an implicit scope |
| 239 | // starting at the second if statement, and it contains |
| 240 | // the final else, so the outermost offending scope |
| 241 | // really is LINE+1 (like in the previous test), |
| 242 | // even though it looks like it might be LINE+3 instead. |
| 243 | if true { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 244 | goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 245 | } else if false { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 246 | } else { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 247 | L: |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /* Want to enable these tests but gofmt mangles them. Issue 1972. |
| 252 | |
| 253 | func _() { |
| 254 | // This one is okay, because the else is in the |
| 255 | // implicit whole-if block and has no inner block |
| 256 | // (no { }) around it. |
| 257 | if true { |
| 258 | goto L |
| 259 | } else |
| 260 | L: |
| 261 | } |
| 262 | |
| 263 | func _() { |
| 264 | // Still not okay. |
Ian Lance Taylor | f1aefc0 | 2011-09-20 14:45:54 -0700 | [diff] [blame] | 265 | if true { //// GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 266 | L: |
| 267 | } else |
Ian Lance Taylor | f1aefc0 | 2011-09-20 14:45:54 -0700 | [diff] [blame] | 268 | goto L //// ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | */ |
| 272 | |
| 273 | // for |
| 274 | |
| 275 | func _() { |
| 276 | for { |
| 277 | goto L |
| 278 | } |
| 279 | L: |
| 280 | } |
| 281 | |
| 282 | func _() { |
| 283 | for { |
| 284 | goto L |
| 285 | L: |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 290 | for { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 291 | L: |
| 292 | } |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 293 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 297 | for { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 298 | goto L |
| 299 | L1: |
| 300 | } |
| 301 | L: |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 302 | goto L1 // ERROR "goto L1 jumps into block starting at LINE-5|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 306 | for i < n { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 307 | L: |
| 308 | } |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 309 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 313 | for i = 0; i < n; i++ { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 314 | L: |
| 315 | } |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 316 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 320 | for i = range x { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 321 | L: |
| 322 | } |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 323 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 327 | for i = range c { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 328 | L: |
| 329 | } |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 330 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 334 | for i = range m { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 335 | L: |
| 336 | } |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 337 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | func _() { |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 341 | for i = range s { // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 342 | L: |
| 343 | } |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 344 | goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | // switch |
| 348 | |
| 349 | func _() { |
| 350 | L: |
| 351 | switch i { |
| 352 | case 0: |
| 353 | goto L |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | func _() { |
| 358 | L: |
| 359 | switch i { |
| 360 | case 0: |
| 361 | |
| 362 | default: |
| 363 | goto L |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func _() { |
| 368 | switch i { |
| 369 | case 0: |
| 370 | |
| 371 | default: |
| 372 | L: |
| 373 | goto L |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | func _() { |
| 378 | switch i { |
| 379 | case 0: |
| 380 | |
| 381 | default: |
| 382 | goto L |
| 383 | L: |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | func _() { |
| 388 | switch i { |
| 389 | case 0: |
| 390 | goto L |
| 391 | L: |
| 392 | ; |
| 393 | default: |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 398 | goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 399 | switch i { |
| 400 | case 0: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 401 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 406 | goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 407 | switch i { |
| 408 | case 0: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 409 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 410 | ; |
| 411 | default: |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 416 | goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 417 | switch i { |
| 418 | case 0: |
| 419 | default: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 420 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
| 424 | func _() { |
| 425 | switch i { |
| 426 | default: |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 427 | goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 428 | case 0: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 429 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
| 433 | func _() { |
| 434 | switch i { |
| 435 | case 0: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 436 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 437 | ; |
| 438 | default: |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 439 | goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
| 443 | // select |
| 444 | // different from switch. the statement has no implicit block around it. |
| 445 | |
| 446 | func _() { |
| 447 | L: |
| 448 | select { |
| 449 | case <-c: |
| 450 | goto L |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | func _() { |
| 455 | L: |
| 456 | select { |
| 457 | case c <- 1: |
| 458 | |
| 459 | default: |
| 460 | goto L |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | func _() { |
| 465 | select { |
| 466 | case <-c: |
| 467 | |
| 468 | default: |
| 469 | L: |
| 470 | goto L |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | func _() { |
| 475 | select { |
| 476 | case c <- 1: |
| 477 | |
| 478 | default: |
| 479 | goto L |
| 480 | L: |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | func _() { |
| 485 | select { |
| 486 | case <-c: |
| 487 | goto L |
| 488 | L: |
| 489 | ; |
| 490 | default: |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 495 | goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 496 | select { |
| 497 | case c <- 1: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 498 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
| 502 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 503 | goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 504 | select { |
| 505 | case c <- 1: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 506 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 507 | ; |
| 508 | default: |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | func _() { |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 513 | goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 514 | select { |
| 515 | case <-c: |
| 516 | default: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 517 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
| 521 | func _() { |
| 522 | select { |
| 523 | default: |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 524 | goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 525 | case <-c: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 526 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | |
| 530 | func _() { |
| 531 | select { |
| 532 | case <-c: |
Josh Bleecher Snyder | ffbf209 | 2015-07-20 13:00:28 -0700 | [diff] [blame] | 533 | L: // GCCGO_ERROR "block starts here" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 534 | ; |
| 535 | default: |
Robert Griesemer | bb70f51 | 2017-04-18 17:16:54 -0700 | [diff] [blame] | 536 | goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block" |
Russ Cox | e0a6174 | 2011-06-20 14:06:00 -0400 | [diff] [blame] | 537 | } |
| 538 | } |