1package main
2
3// Tests of method promotion logic.
4
5type A struct{ magic int }
6
7func (a A) x() {
8	if a.magic != 1 {
9		panic(a.magic)
10	}
11}
12func (a *A) y() *A {
13	return a
14}
15
16type B struct{ magic int }
17
18func (b B) p() {
19	if b.magic != 2 {
20		panic(b.magic)
21	}
22}
23func (b *B) q() {
24	if b != theC.B {
25		panic("oops")
26	}
27}
28
29type I interface {
30	f()
31}
32
33type impl struct{ magic int }
34
35func (i impl) f() {
36	if i.magic != 3 {
37		panic("oops")
38	}
39}
40
41type C struct {
42	A
43	*B
44	I
45}
46
47func assert(cond bool) {
48	if !cond {
49		panic("failed")
50	}
51}
52
53var theC = C{
54	A: A{1},
55	B: &B{2},
56	I: impl{3},
57}
58
59func addr() *C {
60	return &theC
61}
62
63func value() C {
64	return theC
65}
66
67func main() {
68	// address
69	addr().x()
70	if addr().y() != &theC.A {
71		panic("oops")
72	}
73	addr().p()
74	addr().q()
75	addr().f()
76
77	// addressable value
78	var c C = value()
79	c.x()
80	if c.y() != &c.A {
81		panic("oops")
82	}
83	c.p()
84	c.q()
85	c.f()
86
87	// non-addressable value
88	value().x()
89	// value().y() // not in method set
90	value().p()
91	value().q()
92	value().f()
93}
94