Russ Cox | 2e1bb4a | 2008-10-04 02:51:03 -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 | 839a684 | 2009-01-20 14:40:40 -0800 | [diff] [blame] | 9 | type S string |
| 10 | type S1 string |
| 11 | type I int |
| 12 | type I1 int |
| 13 | type T struct { x int } |
| 14 | type T1 T |
Russ Cox | 2e1bb4a | 2008-10-04 02:51:03 -0700 | [diff] [blame] | 15 | |
| 16 | func (s S) val() int { return 1 } |
| 17 | func (s *S1) val() int { return 2 } |
| 18 | func (i I) val() int { return 3 } |
| 19 | func (i *I1) val() int { return 4 } |
Russ Cox | 2e1bb4a | 2008-10-04 02:51:03 -0700 | [diff] [blame] | 20 | //func (t T) val() int { return 7 } |
| 21 | func (t *T1) val() int { return 8 } |
| 22 | |
Russ Cox | 839a684 | 2009-01-20 14:40:40 -0800 | [diff] [blame] | 23 | type Val interface { |
Russ Cox | 2e1bb4a | 2008-10-04 02:51:03 -0700 | [diff] [blame] | 24 | val() int |
| 25 | } |
| 26 | |
| 27 | func val(v Val) int { |
| 28 | return v.val() |
| 29 | } |
| 30 | |
| 31 | func main() { |
| 32 | var s S; |
| 33 | var ps *S1; |
| 34 | var i I; |
| 35 | var pi *I1; |
Russ Cox | 983f06b | 2008-10-07 12:31:31 -0700 | [diff] [blame] | 36 | var pt *T1; |
Russ Cox | 2e1bb4a | 2008-10-04 02:51:03 -0700 | [diff] [blame] | 37 | |
| 38 | if s.val() != 1 { panicln("s.val:", s.val()) } |
| 39 | if ps.val() != 2 { panicln("ps.val:", ps.val()) } |
| 40 | if i.val() != 3 { panicln("i.val:", i.val()) } |
| 41 | if pi.val() != 4 { panicln("pi.val:", pi.val()) } |
Russ Cox | 2e1bb4a | 2008-10-04 02:51:03 -0700 | [diff] [blame] | 42 | // if t.val() != 7 { panicln("t.val:", t.val()) } |
| 43 | if pt.val() != 8 { panicln("pt.val:", pt.val()) } |
| 44 | |
| 45 | if val(s) != 1 { panicln("s.val:", val(s)) } |
| 46 | if val(ps) != 2 { panicln("ps.val:", val(ps)) } |
| 47 | if val(i) != 3 { panicln("i.val:", val(i)) } |
| 48 | if val(pi) != 4 { panicln("pi.val:", val(pi)) } |
Russ Cox | 2e1bb4a | 2008-10-04 02:51:03 -0700 | [diff] [blame] | 49 | // if val(t) != 7 { panicln("t.val:", val(t)) } |
| 50 | if val(pt) != 8 { panicln("pt.val:", val(pt)) } |
| 51 | |
| 52 | } |