Russ Cox | 2b1c9b4 | 2012-02-16 23:49:30 -0500 | [diff] [blame] | 1 | // run |
Russ Cox | ee2d512 | 2009-09-02 09:09:32 -0700 | [diff] [blame] | 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 | |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 9 | type T1 struct { |
| 10 | x, y int |
| 11 | } |
| 12 | type T2 struct { |
| 13 | z, w byte |
| 14 | } |
Russ Cox | ee2d512 | 2009-09-02 09:09:32 -0700 | [diff] [blame] | 15 | type T3 T1 |
| 16 | |
| 17 | type MyInt int |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 18 | |
| 19 | func (MyInt) m(*T1) {} |
Russ Cox | ee2d512 | 2009-09-02 09:09:32 -0700 | [diff] [blame] | 20 | |
| 21 | func main() { |
| 22 | { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 23 | var i interface{} = new(T1) |
| 24 | _, ok1 := i.(*T1) |
| 25 | _, ok2 := i.(*T2) |
| 26 | _, ok3 := i.(*T3) |
Russ Cox | ee2d512 | 2009-09-02 09:09:32 -0700 | [diff] [blame] | 27 | if !ok1 || ok2 || ok3 { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 28 | println("*T1", ok1, ok2, ok3) |
| 29 | panic("fail") |
Russ Cox | ee2d512 | 2009-09-02 09:09:32 -0700 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 33 | var i interface{} = MyInt(0) |
| 34 | _, ok1 := i.(interface { |
| 35 | m(*T1) |
| 36 | }) |
| 37 | _, ok2 := i.(interface { |
| 38 | m(*T2) |
| 39 | }) |
| 40 | _, ok3 := i.(interface { |
| 41 | m(*T3) |
| 42 | }) |
Russ Cox | ee2d512 | 2009-09-02 09:09:32 -0700 | [diff] [blame] | 43 | if !ok1 || ok2 || ok3 { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 44 | println("T", ok1, ok2, ok3) |
| 45 | panic("fail") |
Russ Cox | ee2d512 | 2009-09-02 09:09:32 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |