1 // errchk $G -e $D/$F.go
3 // Copyright 2011 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Each test is in a separate function just so that if the
8 // compiler stops processing after one error, we don't
21 // goto after declaration okay
29 // goto before declaration okay
37 // goto across declaration not okay
39 goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"
40 x := 1 // GCCGO_ERROR "defined here"
45 // goto across declaration in inner scope okay
55 // goto across declaration after inner scope not okay
57 goto L // ERROR "goto L jumps over declaration of x at LINE+5|goto jumps over declaration"
62 x := 1 // GCCGO_ERROR "defined here"
67 // goto across declaration in reverse okay
75 // error shows first offending variable
77 goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"
78 x := 1 // GCCGO_ERROR "defined here"
85 // goto not okay even if code path is dead
87 goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"
88 x := 1 // GCCGO_ERROR "defined here"
96 // goto into outer block okay
104 // goto backward into outer block okay
112 // goto into inner block not okay
114 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
115 { // GCCGO_ERROR "block starts here"
120 // goto backward into inner block still not okay
122 { // GCCGO_ERROR "block starts here"
125 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
128 // error shows first (outermost) offending block
130 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
133 { // GCCGO_ERROR "block starts here"
140 // error prefers block diagnostic over declaration diagnostic
142 goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block"
145 { // GCCGO_ERROR "block starts here"
150 // many kinds of blocks, all invalid to jump into or among,
151 // but valid to jump out of
179 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
180 if true { // GCCGO_ERROR "block starts here"
186 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
187 if true { // GCCGO_ERROR "block starts here"
194 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
196 } else { // GCCGO_ERROR "block starts here"
202 if false { // GCCGO_ERROR "block starts here"
205 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
211 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
212 } else { // GCCGO_ERROR "block starts here"
219 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
220 } else if false { // GCCGO_ERROR "block starts here"
227 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
228 } else if false { // GCCGO_ERROR "block starts here"
235 // This one is tricky. There is an implicit scope
236 // starting at the second if statement, and it contains
237 // the final else, so the outermost offending scope
238 // really is LINE+1 (like in the previous test),
239 // even though it looks like it might be LINE+3 instead.
241 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
243 } else { // GCCGO_ERROR "block starts here"
248 /* Want to enable these tests but gofmt mangles them. Issue 1972.
251 // This one is okay, because the else is in the
252 // implicit whole-if block and has no inner block
253 // (no { }) around it.
262 if true { //// GCCGO_ERROR "block starts here"
265 goto L //// ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
287 for { // GCCGO_ERROR "block starts here"
290 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
294 for { // GCCGO_ERROR "block starts here"
299 goto L1 // ERROR "goto L1 jumps into block starting at LINE-5|goto jumps into block"
303 for i < n { // GCCGO_ERROR "block starts here"
306 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
310 for i = 0; i < n; i++ { // GCCGO_ERROR "block starts here"
313 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
317 for i = range x { // GCCGO_ERROR "block starts here"
320 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
324 for i = range c { // GCCGO_ERROR "block starts here"
327 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
331 for i = range m { // GCCGO_ERROR "block starts here"
334 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
338 for i = range s { // GCCGO_ERROR "block starts here"
341 goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
395 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
398 L: // GCCGO_ERROR "block starts here"
403 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
406 L: // GCCGO_ERROR "block starts here"
413 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
417 L: // GCCGO_ERROR "block starts here"
424 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
426 L: // GCCGO_ERROR "block starts here"
433 L: // GCCGO_ERROR "block starts here"
436 goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"
441 // different from switch. the statement has no implicit block around it.
492 goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block"
495 L: // GCCGO_ERROR "block starts here"
500 goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block"
503 L: // GCCGO_ERROR "block starts here"
510 goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block"
514 L: // GCCGO_ERROR "block starts here"
521 goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
523 L: // GCCGO_ERROR "block starts here"
530 L: // GCCGO_ERROR "block starts here"
533 goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"