| 
									
										
										
										
											2012-02-16 23:50:37 -05:00
										 |  |  | // errorcheck | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-10 14:32:26 -07:00
										 |  |  | // Copyright 2011 The Go Authors. All rights reserved. | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | // Use of this source code is governed by a BSD-style | 
					
						
							|  |  |  | // license that can be found in the LICENSE file. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 18:47:26 +11:00
										 |  |  | // Verify that erroneous labels are caught by the compiler. | 
					
						
							|  |  |  | // This set is caught by pass 2. That's why this file is label1.go. | 
					
						
							|  |  |  | // Does not compile. | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var x int | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-11 20:31:41 +01:00
										 |  |  | func f1() { | 
					
						
							|  |  |  | 	switch x { | 
					
						
							|  |  |  | 	case 1: | 
					
						
							|  |  |  | 		continue // ERROR "continue is not in a loop$" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	select { | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		continue // ERROR "continue is not in a loop$" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f2() { | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | L1: | 
					
						
							|  |  |  | 	for { | 
					
						
							|  |  |  | 		if x == 0 { | 
					
						
							|  |  |  | 			break L1 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if x == 1 { | 
					
						
							|  |  |  | 			continue L1 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		goto L1 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | L2: | 
					
						
							|  |  |  | 	select { | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		if x == 0 { | 
					
						
							|  |  |  | 			break L2 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if x == 1 { | 
					
						
							| 
									
										
										
										
											2017-04-11 20:31:41 +01:00
										 |  |  | 			continue L2 // ERROR "invalid continue label .*L2|continue is not in a loop$" | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		goto L2 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 15:39:14 -07:00
										 |  |  | 	for { | 
					
						
							|  |  |  | 		if x == 1 { | 
					
						
							|  |  |  | 			continue L2 // ERROR "invalid continue label .*L2" | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | L3: | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case x > 10: | 
					
						
							|  |  |  | 		if x == 11 { | 
					
						
							|  |  |  | 			break L3 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if x == 12 { | 
					
						
							| 
									
										
										
										
											2017-04-11 20:31:41 +01:00
										 |  |  | 			continue L3 // ERROR "invalid continue label .*L3|continue is not in a loop$" | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		goto L3 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | L4: | 
					
						
							|  |  |  | 	if true { | 
					
						
							|  |  |  | 		if x == 13 { | 
					
						
							| 
									
										
										
										
											2011-03-25 10:36:46 -07:00
										 |  |  | 			break L4 // ERROR "invalid break label .*L4" | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if x == 14 { | 
					
						
							| 
									
										
										
										
											2017-04-11 20:31:41 +01:00
										 |  |  | 			continue L4 // ERROR "invalid continue label .*L4|continue is not in a loop$" | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if x == 15 { | 
					
						
							|  |  |  | 			goto L4 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | L5: | 
					
						
							| 
									
										
										
										
											2017-04-11 20:31:41 +01:00
										 |  |  | 	f2() | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 	if x == 16 { | 
					
						
							| 
									
										
										
										
											2011-03-25 10:36:46 -07:00
										 |  |  | 		break L5 // ERROR "invalid break label .*L5" | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if x == 17 { | 
					
						
							| 
									
										
										
										
											2017-04-11 20:31:41 +01:00
										 |  |  | 		continue L5 // ERROR "invalid continue label .*L5|continue is not in a loop$" | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if x == 18 { | 
					
						
							|  |  |  | 		goto L5 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for { | 
					
						
							|  |  |  | 		if x == 19 { | 
					
						
							| 
									
										
										
										
											2011-03-25 10:36:46 -07:00
										 |  |  | 			break L1 // ERROR "invalid break label .*L1" | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if x == 20 { | 
					
						
							| 
									
										
										
										
											2011-03-25 10:36:46 -07:00
										 |  |  | 			continue L1 // ERROR "invalid continue label .*L1" | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if x == 21 { | 
					
						
							|  |  |  | 			goto L1 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-20 15:39:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-11 20:31:41 +01:00
										 |  |  | 	continue // ERROR "continue is not in a loop$" | 
					
						
							| 
									
										
										
										
											2015-07-20 15:39:14 -07:00
										 |  |  | 	for { | 
					
						
							|  |  |  | 		continue on // ERROR "continue label not defined: on" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-11 20:31:41 +01:00
										 |  |  | 	break // ERROR "break is not in a loop, switch, or select" | 
					
						
							| 
									
										
										
										
											2015-07-20 15:39:14 -07:00
										 |  |  | 	for { | 
					
						
							|  |  |  | 		break dance // ERROR "break label not defined: dance" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for { | 
					
						
							|  |  |  | 		switch x { | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-03-15 14:05:37 -04:00
										 |  |  | } |