1package main
2
3// Test of promotion of methods of an interface embedded within a
4// struct.  In particular, this test exercises that the correct
5// method is called.
6
7type I interface {
8	one() int
9	two() string
10}
11
12type S struct {
13	I
14}
15
16type impl struct{}
17
18func (impl) one() int {
19	return 1
20}
21
22func (impl) two() string {
23	return "two"
24}
25
26func main() {
27	var s S
28	s.I = impl{}
29	if one := s.I.one(); one != 1 {
30		panic(one)
31	}
32	if one := s.one(); one != 1 {
33		panic(one)
34	}
35	closOne := s.I.one
36	if one := closOne(); one != 1 {
37		panic(one)
38	}
39	closOne = s.one
40	if one := closOne(); one != 1 {
41		panic(one)
42	}
43
44	if two := s.I.two(); two != "two" {
45		panic(two)
46	}
47	if two := s.two(); two != "two" {
48		panic(two)
49	}
50	closTwo := s.I.two
51	if two := closTwo(); two != "two" {
52		panic(two)
53	}
54	closTwo = s.two
55	if two := closTwo(); two != "two" {
56		panic(two)
57	}
58}
59