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 9package main 10 11import "reflect" 12 13func typeof(x interface{}) string { return reflect.TypeOf(x).String() } 14 15func f() int { return 0 } 16 17func g() int { return 0 } 18 19type T func() int 20 21var m = map[string]T{"f": f} 22 23type A int 24type B int 25 26var a A = 1 27var b B = 2 28var x int 29 30func 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} 47