blob: 0a75663d0647f58ace06f60a1fc76c252939da4e [file] [log] [blame]
Russ Cox8f194bf2009-03-12 19:04:38 -07001// $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
7package main
8
Russ Cox1af3edc2009-07-03 09:45:15 -07009import "reflect"
Russ Cox8f194bf2009-03-12 19:04:38 -070010
Russ Cox07abf1c2011-04-25 13:39:36 -040011func typeof(x interface{}) string { return reflect.TypeOf(x).String() }
Russ Cox8f194bf2009-03-12 19:04:38 -070012
Rob Pike325cf8e2010-03-24 16:46:53 -070013func f() int { return 0 }
Russ Cox8f194bf2009-03-12 19:04:38 -070014
Rob Pike325cf8e2010-03-24 16:46:53 -070015func g() int { return 0 }
Russ Cox8f194bf2009-03-12 19:04:38 -070016
17type T func() int
18
Rob Pike325cf8e2010-03-24 16:46:53 -070019var m = map[string]T{"f": f}
Russ Cox8f194bf2009-03-12 19:04:38 -070020
21type A int
22type B int
23
Rob Pike325cf8e2010-03-24 16:46:53 -070024var a A = 1
25var b B = 2
26var x int
Russ Cox8f194bf2009-03-12 19:04:38 -070027
28func main() {
Rob Pike325cf8e2010-03-24 16:46:53 -070029 want := typeof(g)
Russ Cox8f194bf2009-03-12 19:04:38 -070030 if t := typeof(f); t != want {
Rob Pike325cf8e2010-03-24 16:46:53 -070031 println("type of f is", t, "want", want)
32 panic("fail")
Russ Cox8f194bf2009-03-12 19:04:38 -070033 }
34
Rob Pike325cf8e2010-03-24 16:46:53 -070035 want = typeof(a)
Russ Cox8f194bf2009-03-12 19:04:38 -070036 if t := typeof(+a); t != want {
Rob Pike325cf8e2010-03-24 16:46:53 -070037 println("type of +a is", t, "want", want)
38 panic("fail")
Russ Cox8f194bf2009-03-12 19:04:38 -070039 }
Rob Pike325cf8e2010-03-24 16:46:53 -070040 if t := typeof(a + 0); t != want {
41 println("type of a+0 is", t, "want", want)
42 panic("fail")
Russ Cox8f194bf2009-03-12 19:04:38 -070043 }
Russ Cox8f194bf2009-03-12 19:04:38 -070044}