| 
									
										
										
										
											2012-02-16 23:50:37 -05:00
										 |  |  | // errorcheck | 
					
						
							| 
									
										
										
										
											2009-05-21 14:46:13 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Copyright 2009 The Go Authors. All rights reserved. | 
					
						
							|  |  |  | // 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 initialization expressions are caught by the compiler | 
					
						
							|  |  |  | // Does not compile. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 14:46:13 -07:00
										 |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type S struct { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	A, B, C, X, Y, Z int | 
					
						
							| 
									
										
										
										
											2009-05-21 14:46:13 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type T struct { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	S | 
					
						
							| 
									
										
										
										
											2009-05-21 14:46:13 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var x = 1 | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | var a1 = S { 0, X: 1 }	// ERROR "mixture|undefined" | 
					
						
							|  |  |  | var a2 = S { Y: 3, Z: 2, Y: 3 } // ERROR "duplicate" | 
					
						
							| 
									
										
										
										
											2011-08-16 11:14:26 -04:00
										 |  |  | var a3 = T { S{}, 2, 3, 4, 5, 6 }	// ERROR "convert|too many" | 
					
						
							| 
									
										
										
										
											2009-05-31 11:18:52 -07:00
										 |  |  | var a4 = [5]byte{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }	// ERROR "index|too many" | 
					
						
							| 
									
										
										
										
											2009-05-21 14:46:13 -07:00
										 |  |  | var a5 = []byte { x: 2 }	// ERROR "index" | 
					
						
							| 
									
										
										
										
											2017-04-22 15:28:58 +02:00
										 |  |  | var a6 = []byte{1: 1, 2: 2, 1: 3}	// ERROR "duplicate index" | 
					
						
							| 
									
										
										
										
											2009-05-21 14:46:13 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | var ok1 = S { }	// should be ok | 
					
						
							| 
									
										
										
										
											2009-05-21 16:31:10 -07:00
										 |  |  | var ok2 = T { S: ok1 }	// should be ok | 
					
						
							| 
									
										
										
										
											2012-12-17 11:05:58 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | // These keys can be computed at compile time but they are | 
					
						
							|  |  |  | // not constants as defined by the spec, so they do not trigger | 
					
						
							|  |  |  | // compile-time errors about duplicate key values. | 
					
						
							|  |  |  | // See issue 4555. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Key struct {X, Y int} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var _ = map[Key]string{ | 
					
						
							|  |  |  | 	Key{1,2}: "hello", | 
					
						
							|  |  |  | 	Key{1,2}: "world", | 
					
						
							|  |  |  | } |