github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/src/go/types/testdata/conversions.src (about) 1 // Copyright 2012 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 // conversions 6 7 package conversions 8 9 import "unsafe" 10 11 // argument count 12 var ( 13 _ = int() /* ERROR "missing argument" */ 14 _ = int(1, 2 /* ERROR "too many arguments" */ ) 15 ) 16 17 // numeric constant conversions are in const1.src. 18 19 func string_conversions() { 20 const A = string(65) 21 assert(A == "A") 22 const E = string(-1) 23 assert(E == "\uFFFD") 24 assert(E == string(1234567890)) 25 26 type myint int 27 assert(A == string(myint(65))) 28 29 type mystring string 30 const _ mystring = mystring("foo") 31 32 const _ = string(true /* ERROR "cannot convert" */ ) 33 const _ = string(1.2 /* ERROR "cannot convert" */ ) 34 const _ = string(nil /* ERROR "cannot convert" */ ) 35 } 36 37 func interface_conversions() { 38 type E interface{} 39 40 type I1 interface{ 41 m1() 42 } 43 44 type I2 interface{ 45 m1() 46 m2(x int) 47 } 48 49 type I3 interface{ 50 m1() 51 m2() int 52 } 53 54 var e E 55 var i1 I1 56 var i2 I2 57 var i3 I3 58 59 _ = E(0) 60 _ = E(nil) 61 _ = E(e) 62 _ = E(i1) 63 _ = E(i2) 64 65 _ = I1(0 /* ERROR "cannot convert" */ ) 66 _ = I1(nil) 67 _ = I1(i1) 68 _ = I1(e /* ERROR "cannot convert" */ ) 69 _ = I1(i2) 70 71 _ = I2(nil) 72 _ = I2(i1 /* ERROR "cannot convert" */ ) 73 _ = I2(i2) 74 _ = I2(i3 /* ERROR "cannot convert" */ ) 75 76 _ = I3(nil) 77 _ = I3(i1 /* ERROR "cannot convert" */ ) 78 _ = I3(i2 /* ERROR "cannot convert" */ ) 79 _ = I3(i3) 80 81 // TODO(gri) add more tests, improve error message 82 } 83 84 func issue6326() { 85 type T unsafe.Pointer 86 var x T 87 _ = uintptr(x) // see issue 6326 88 }