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