...
Run Format

Text file src/go/types/testdata/labels.src

Documentation: go/types/testdata

     1	// Copyright 2011 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	// This file is a modified concatenation of the files
     6	// $GOROOT/test/label.go and $GOROOT/test/label1.go.
     7	
     8	package labels
     9	
    10	var x int
    11	
    12	func f0() {
    13	L1 /* ERROR "label L1 declared but not used" */ :
    14		for {
    15		}
    16	L2 /* ERROR "label L2 declared but not used" */ :
    17		select {
    18		}
    19	L3 /* ERROR "label L3 declared but not used" */ :
    20		switch {
    21		}
    22	L4 /* ERROR "label L4 declared but not used" */ :
    23		if true {
    24		}
    25	L5 /* ERROR "label L5 declared but not used" */ :
    26		f0()
    27	L6:
    28		f0()
    29	L6 /* ERROR "label L6 already declared" */ :
    30		f0()
    31		if x == 20 {
    32			goto L6
    33		}
    34	
    35	L7:
    36		for {
    37			break L7
    38			break L8 /* ERROR "invalid break label L8" */
    39		}
    40	
    41	// A label must be directly associated with a switch, select, or
    42	// for statement; it cannot be the label of a labeled statement.
    43	
    44	L7a /* ERROR "declared but not used" */ : L7b:
    45		for {
    46			break L7a /* ERROR "invalid break label L7a" */
    47			continue L7a /* ERROR "invalid continue label L7a" */
    48			continue L7b
    49		}
    50	
    51	L8:
    52		for {
    53			if x == 21 {
    54				continue L8
    55				continue L7 /* ERROR "invalid continue label L7" */
    56			}
    57		}
    58	
    59	L9:
    60		switch {
    61		case true:
    62			break L9
    63		defalt /* ERROR "label defalt declared but not used" */ :
    64		}
    65	
    66	L10:
    67		select {
    68		default:
    69			break L10
    70			break L9 /* ERROR "invalid break label L9" */
    71		}
    72	
    73		goto L10a
    74	L10a: L10b:
    75		select {
    76		default:
    77			break L10a /* ERROR "invalid break label L10a" */
    78			break L10b
    79			continue L10b /* ERROR "invalid continue label L10b" */
    80		}
    81	}
    82	
    83	func f1() {
    84	L1:
    85		for {
    86			if x == 0 {
    87				break L1
    88			}
    89			if x == 1 {
    90				continue L1
    91			}
    92			goto L1
    93		}
    94	
    95	L2:
    96		select {
    97		default:
    98			if x == 0 {
    99				break L2
   100			}
   101			if x == 1 {
   102				continue L2 /* ERROR "invalid continue label L2" */
   103			}
   104			goto L2
   105		}
   106	
   107	L3:
   108		switch {
   109		case x > 10:
   110			if x == 11 {
   111				break L3
   112			}
   113			if x == 12 {
   114				continue L3 /* ERROR "invalid continue label L3" */
   115			}
   116			goto L3
   117		}
   118	
   119	L4:
   120		if true {
   121			if x == 13 {
   122				break L4 /* ERROR "invalid break label L4" */
   123			}
   124			if x == 14 {
   125				continue L4 /* ERROR "invalid continue label L4" */
   126			}
   127			if x == 15 {
   128				goto L4
   129			}
   130		}
   131	
   132	L5:
   133		f1()
   134		if x == 16 {
   135			break L5 /* ERROR "invalid break label L5" */
   136		}
   137		if x == 17 {
   138			continue L5 /* ERROR "invalid continue label L5" */
   139		}
   140		if x == 18 {
   141			goto L5
   142		}
   143	
   144		for {
   145			if x == 19 {
   146				break L1 /* ERROR "invalid break label L1" */
   147			}
   148			if x == 20 {
   149				continue L1 /* ERROR "invalid continue label L1" */
   150			}
   151			if x == 21 {
   152				goto L1
   153			}
   154		}
   155	}
   156	
   157	// Additional tests not in the original files.
   158	
   159	func f2() {
   160	L1 /* ERROR "label L1 declared but not used" */ :
   161		if x == 0 {
   162			for {
   163				continue L1 /* ERROR "invalid continue label L1" */
   164			}
   165		}
   166	}
   167	
   168	func f3() {
   169	L1:
   170	L2:
   171	L3:
   172		for {
   173			break L1 /* ERROR "invalid break label L1" */
   174			break L2 /* ERROR "invalid break label L2" */
   175			break L3
   176			continue L1 /* ERROR "invalid continue label L1" */
   177			continue L2 /* ERROR "invalid continue label L2" */
   178			continue L3
   179			goto L1
   180			goto L2
   181			goto L3
   182		}
   183	}
   184	
   185	// Blank labels are never declared.
   186	
   187	func f4() {
   188	_:
   189	_: // multiple blank labels are ok
   190		goto _ /* ERROR "label _ not declared" */
   191	}
   192	
   193	func f5() {
   194	_:
   195		for {
   196			break _ /* ERROR "invalid break label _" */
   197			continue _ /* ERROR "invalid continue label _" */
   198		}
   199	}
   200	
   201	func f6() {
   202	_:
   203		switch {
   204		default:
   205			break _ /* ERROR "invalid break label _" */
   206		}
   207	}

View as plain text