| 
									
										
										
										
											2012-02-16 23:51:04 -05:00
										 |  |  | // errorcheck | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-10 14:32:26 -07:00
										 |  |  | // Copyright 2009 The Go Authors. All rights reserved. | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | // Use of this source code is governed by a BSD-style | 
					
						
							|  |  |  | // license that can be found in the LICENSE file. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Test that basic operations on named types are valid | 
					
						
							|  |  |  | // and preserve the type. | 
					
						
							| 
									
										
										
										
											2012-02-24 11:48:19 +11:00
										 |  |  | // Does not compile. | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Bool bool | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Map map[int]int | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | func (Map) M() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | type Slice []byte | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var slice Slice | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func asBool(Bool)     {} | 
					
						
							|  |  |  | func asString(String) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type String string | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							| 
									
										
										
										
											2012-02-21 22:54:07 -05:00
										 |  |  | 		b    Bool = true | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 		i, j int | 
					
						
							|  |  |  | 		c    = make(chan int) | 
					
						
							|  |  |  | 		m    = make(Map) | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 	asBool(b) | 
					
						
							|  |  |  | 	asBool(!b) | 
					
						
							| 
									
										
										
										
											2012-02-21 22:54:07 -05:00
										 |  |  | 	asBool(true) | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 	asBool(*&b) | 
					
						
							|  |  |  | 	asBool(Bool(true)) | 
					
						
							| 
									
										
										
										
											2012-02-22 00:29:37 -05:00
										 |  |  | 	asBool(1 != 2) // ok now | 
					
						
							|  |  |  | 	asBool(i < j)  // ok now | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-11 16:11:55 -07:00
										 |  |  | 	_, b = m[2] // ok now | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 	var inter interface{} | 
					
						
							| 
									
										
										
										
											2014-08-11 16:11:55 -07:00
										 |  |  | 	_, b = inter.(Map) // ok now | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 	_ = b | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 	var minter interface { | 
					
						
							|  |  |  | 		M() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-11 16:11:55 -07:00
										 |  |  | 	_, b = minter.(Map) // ok now | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 	_ = b | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 14:47:44 -05:00
										 |  |  | 	_, bb := <-c | 
					
						
							|  |  |  | 	asBool(bb) // ERROR "cannot use.*type bool.*as type Bool" | 
					
						
							| 
									
										
										
										
											2014-08-11 16:11:55 -07:00
										 |  |  | 	_, b = <-c // ok now | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | 	_ = b | 
					
						
							| 
									
										
										
										
											2009-09-24 17:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	asString(String(slice)) // ok | 
					
						
							| 
									
										
										
										
											2010-06-08 18:50:02 -07:00
										 |  |  | } |