1// errorcheck 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 and *interface values. 8 9package main 10 11import "os" 12 13const Value = 1e12 14 15type Inter interface { 16 M() int64 17} 18 19type T int64 20 21func (t T) M() int64 { return int64(t) } 22 23var t = T(Value) 24var pt = &t 25var ti Inter = t 26var pti = &ti 27 28type S struct{ Inter } 29 30var s = S{ti} 31var ps = &s 32 33type SP struct{ *Inter } // ERROR "interface" 34 35var i Inter 36var pi = &i 37 38var ok = true 39 40func check(s string, v int64) { 41 if v != Value { 42 println(s, v) 43 ok = false 44 } 45} 46 47func main() { 48 check("t.M()", t.M()) 49 check("pt.M()", pt.M()) 50 check("ti.M()", ti.M()) 51 check("pti.M()", pti.M()) // ERROR "pointer to interface, not interface|no field or method M" 52 check("s.M()", s.M()) 53 check("ps.M()", ps.M()) 54 55 i = t 56 check("i = t; i.M()", i.M()) 57 check("i = t; pi.M()", pi.M()) // ERROR "pointer to interface, not interface|no field or method M" 58 59 i = pt 60 check("i = pt; i.M()", i.M()) 61 check("i = pt; pi.M()", pi.M()) // ERROR "pointer to interface, not interface|no field or method M" 62 63 i = s 64 check("i = s; i.M()", i.M()) 65 check("i = s; pi.M()", pi.M()) // ERROR "pointer to interface, not interface|no field or method M" 66 67 i = ps 68 check("i = ps; i.M()", i.M()) 69 check("i = ps; pi.M()", pi.M()) // ERROR "pointer to interface, not interface|no field or method M" 70 71 if !ok { 72 println("BUG: interface10") 73 os.Exit(1) 74 } 75} 76