github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/test/convert.go (about) 1 // run 2 3 // Copyright 2009 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // Test types of constant expressions, using reflect. 8 9 package main 10 11 import "reflect" 12 13 func typeof(x interface{}) string { return reflect.TypeOf(x).String() } 14 15 func f() int { return 0 } 16 17 func g() int { return 0 } 18 19 type T func() int 20 21 var m = map[string]T{"f": f} 22 23 type A int 24 type B int 25 26 var a A = 1 27 var b B = 2 28 var x int 29 30 func main() { 31 want := typeof(g) 32 if t := typeof(f); t != want { 33 println("type of f is", t, "want", want) 34 panic("fail") 35 } 36 37 want = typeof(a) 38 if t := typeof(+a); t != want { 39 println("type of +a is", t, "want", want) 40 panic("fail") 41 } 42 if t := typeof(a + 0); t != want { 43 println("type of a+0 is", t, "want", want) 44 panic("fail") 45 } 46 }