| 
									
										
										
										
											2012-02-16 23:48:57 -05:00
										 |  |  | // errorcheck | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-10 14:32:26 -07:00
										 |  |  | // Copyright 2011 The Go Authors. All rights reserved. | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | // Use of this source code is governed by a BSD-style | 
					
						
							|  |  |  | // license that can be found in the LICENSE file. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 13:19:43 +11:00
										 |  |  | // Verify that illegal conversions involving strings are detected. | 
					
						
							|  |  |  | // Does not compile. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Tbyte []byte | 
					
						
							|  |  |  | type Trune []rune | 
					
						
							|  |  |  | type Tint64 []int64 | 
					
						
							|  |  |  | type Tstring string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							|  |  |  | 	s := "hello" | 
					
						
							|  |  |  | 	sb := []byte("hello") | 
					
						
							|  |  |  | 	sr := []rune("hello") | 
					
						
							|  |  |  | 	si := []int64{'h', 'e', 'l', 'l', 'o'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ts := Tstring(s) | 
					
						
							|  |  |  | 	tsb := Tbyte(sb) | 
					
						
							|  |  |  | 	tsr := Trune(sr) | 
					
						
							|  |  |  | 	tsi := Tint64(si) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_ = string(s) | 
					
						
							|  |  |  | 	_ = []byte(s) | 
					
						
							|  |  |  | 	_ = []rune(s) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = []int64(s) // ERROR "cannot convert.*\[\]int64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Tstring(s) | 
					
						
							|  |  |  | 	_ = Tbyte(s) | 
					
						
							|  |  |  | 	_ = Trune(s) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Tint64(s) // ERROR "cannot convert.*Tint64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_ = string(sb) | 
					
						
							|  |  |  | 	_ = []byte(sb) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = []rune(sb)  // ERROR "cannot convert.*\[\]rune|invalid type conversion" | 
					
						
							|  |  |  | 	_ = []int64(sb) // ERROR "cannot convert.*\[\]int64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Tstring(sb) | 
					
						
							|  |  |  | 	_ = Tbyte(sb) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Trune(sb)  // ERROR "cannot convert.*Trune|invalid type conversion" | 
					
						
							|  |  |  | 	_ = Tint64(sb) // ERROR "cannot convert.*Tint64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_ = string(sr) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = []byte(sr) // ERROR "cannot convert.*\[\]byte|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = []rune(sr) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = []int64(sr) // ERROR "cannot convert.*\[\]int64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Tstring(sr) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Tbyte(sr) // ERROR "cannot convert.*Tbyte|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Trune(sr) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Tint64(sr) // ERROR "cannot convert.*Tint64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = string(si) // ERROR "cannot convert.* string|invalid type conversion" | 
					
						
							|  |  |  | 	_ = []byte(si) // ERROR "cannot convert.*\[\]byte|invalid type conversion" | 
					
						
							|  |  |  | 	_ = []rune(si) // ERROR "cannot convert.*\[\]rune|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = []int64(si) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Tstring(si) // ERROR "cannot convert.*Tstring|invalid type conversion" | 
					
						
							|  |  |  | 	_ = Tbyte(si)   // ERROR "cannot convert.*Tbyte|invalid type conversion" | 
					
						
							|  |  |  | 	_ = Trune(si)   // ERROR "cannot convert.*Trune|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Tint64(si) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_ = string(ts) | 
					
						
							|  |  |  | 	_ = []byte(ts) | 
					
						
							|  |  |  | 	_ = []rune(ts) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = []int64(ts) // ERROR "cannot convert.*\[\]int64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Tstring(ts) | 
					
						
							|  |  |  | 	_ = Tbyte(ts) | 
					
						
							|  |  |  | 	_ = Trune(ts) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Tint64(ts) // ERROR "cannot convert.*Tint64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_ = string(tsb) | 
					
						
							|  |  |  | 	_ = []byte(tsb) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = []rune(tsb)  // ERROR "cannot convert.*\[\]rune|invalid type conversion" | 
					
						
							|  |  |  | 	_ = []int64(tsb) // ERROR "cannot convert.*\[\]int64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Tstring(tsb) | 
					
						
							|  |  |  | 	_ = Tbyte(tsb) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Trune(tsb)  // ERROR "cannot convert.*Trune|invalid type conversion" | 
					
						
							|  |  |  | 	_ = Tint64(tsb) // ERROR "cannot convert.*Tint64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_ = string(tsr) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = []byte(tsr) // ERROR "cannot convert.*\[\]byte|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = []rune(tsr) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = []int64(tsr) // ERROR "cannot convert.*\[\]int64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Tstring(tsr) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Tbyte(tsr) // ERROR "cannot convert.*Tbyte|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Trune(tsr) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Tint64(tsr) // ERROR "cannot convert.*Tint64|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = string(tsi) // ERROR "cannot convert.* string|invalid type conversion" | 
					
						
							|  |  |  | 	_ = []byte(tsi) // ERROR "cannot convert.*\[\]byte|invalid type conversion" | 
					
						
							|  |  |  | 	_ = []rune(tsi) // ERROR "cannot convert.*\[\]rune|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = []int64(tsi) | 
					
						
							| 
									
										
										
										
											2012-01-26 23:06:47 -08:00
										 |  |  | 	_ = Tstring(tsi) // ERROR "cannot convert.*Tstring|invalid type conversion" | 
					
						
							|  |  |  | 	_ = Tbyte(tsi)   // ERROR "cannot convert.*Tbyte|invalid type conversion" | 
					
						
							|  |  |  | 	_ = Trune(tsi)   // ERROR "cannot convert.*Trune|invalid type conversion" | 
					
						
							| 
									
										
										
										
											2011-11-22 12:30:02 -05:00
										 |  |  | 	_ = Tint64(tsi) | 
					
						
							|  |  |  | } |