...
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
     8package labels
     9
    10var x int
    11
    12func f0() {
    13L1 /* ERROR "label L1 declared but not used" */ :
    14	for {
    15	}
    16L2 /* ERROR "label L2 declared but not used" */ :
    17	select {
    18	}
    19L3 /* ERROR "label L3 declared but not used" */ :
    20	switch {
    21	}
    22L4 /* ERROR "label L4 declared but not used" */ :
    23	if true {
    24	}
    25L5 /* ERROR "label L5 declared but not used" */ :
    26	f0()
    27L6:
    28	f0()
    29L6 /* ERROR "label L6 already declared" */ :
    30	f0()
    31	if x == 20 {
    32		goto L6
    33	}
    34
    35L7:
    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
    44L7a /* 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
    51L8:
    52	for {
    53		if x == 21 {
    54			continue L8
    55			continue L7 /* ERROR "invalid continue label L7" */
    56		}
    57	}
    58
    59L9:
    60	switch {
    61	case true:
    62		break L9
    63	defalt /* ERROR "label defalt declared but not used" */ :
    64	}
    65
    66L10:
    67	select {
    68	default:
    69		break L10
    70		break L9 /* ERROR "invalid break label L9" */
    71	}
    72
    73	goto L10a
    74L10a: 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
    83func f1() {
    84L1:
    85	for {
    86		if x == 0 {
    87			break L1
    88		}
    89		if x == 1 {
    90			continue L1
    91		}
    92		goto L1
    93	}
    94
    95L2:
    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
   107L3:
   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
   119L4:
   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
   132L5:
   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
   159func f2() {
   160L1 /* 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
   168func f3() {
   169L1:
   170L2:
   171L3:
   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
   187func f4() {
   188_:
   189_: // multiple blank labels are ok
   190	goto _ /* ERROR "label _ not declared" */
   191}
   192
   193func f5() {
   194_:
   195	for {
   196		break _ /* ERROR "invalid break label _" */
   197		continue _ /* ERROR "invalid continue label _" */
   198	}
   199}
   200
   201func f6() {
   202_:
   203	switch {
   204	default:
   205		break _ /* ERROR "invalid break label _" */
   206	}
   207}

View as plain text