Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 1 | // $G $D/$F.go && $L $F.$A && ./$A.out |
| 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 | package main |
| 8 | |
Russ Cox | 1af3edc | 2009-07-03 09:45:15 -0700 | [diff] [blame] | 9 | import "reflect" |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 10 | |
Russ Cox | 07abf1c | 2011-04-25 13:39:36 -0400 | [diff] [blame] | 11 | func typeof(x interface{}) string { return reflect.TypeOf(x).String() } |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 12 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 13 | func f() int { return 0 } |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 14 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 15 | func g() int { return 0 } |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 16 | |
| 17 | type T func() int |
| 18 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 19 | var m = map[string]T{"f": f} |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 20 | |
| 21 | type A int |
| 22 | type B int |
| 23 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 24 | var a A = 1 |
| 25 | var b B = 2 |
| 26 | var x int |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 27 | |
| 28 | func main() { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 29 | want := typeof(g) |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 30 | if t := typeof(f); t != want { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 31 | println("type of f is", t, "want", want) |
| 32 | panic("fail") |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 35 | want = typeof(a) |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 36 | if t := typeof(+a); t != want { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 37 | println("type of +a is", t, "want", want) |
| 38 | panic("fail") |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 39 | } |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 40 | if t := typeof(a + 0); t != want { |
| 41 | println("type of a+0 is", t, "want", want) |
| 42 | panic("fail") |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 43 | } |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 44 | } |