github.com/yanyiwu/go@v0.0.0-20150106053140-03d6637dbb7f/test/interface/embed.go (about) 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 methods derived from embedded interface values. 8 9 package main 10 11 import "os" 12 13 const Value = 1e12 14 15 type Inter interface { M() int64 } 16 17 type T int64 18 func (t T) M() int64 { return int64(t) } 19 var t = T(Value) 20 var pt = &t 21 var ti Inter = t 22 23 type S struct { Inter } 24 var s = S{ ti } 25 var ps = &s 26 27 var i Inter 28 29 var ok = true 30 31 func check(s string, v int64) { 32 if v != Value { 33 println(s, v) 34 ok = false 35 } 36 } 37 38 func main() { 39 check("t.M()", t.M()) 40 check("pt.M()", pt.M()) 41 check("ti.M()", ti.M()) 42 check("s.M()", s.M()) 43 check("ps.M()", ps.M()) 44 45 i = t 46 check("i = t; i.M()", i.M()) 47 48 i = pt 49 check("i = pt; i.M()", i.M()) 50 51 i = s 52 check("i = s; i.M()", i.M()) 53 54 i = ps 55 check("i = ps; i.M()", i.M()) 56 57 if !ok { 58 println("BUG: interface10") 59 os.Exit(1) 60 } 61 }