blob: 414dc7363637e1157725a77786914ef5b4649d9a [file] [log] [blame]
Alan Donovan1f2812f2013-05-31 16:36:03 -04001package main
2
3// Test of promotion of methods of an interface embedded within a
Alan Donovanfb0642f2013-07-29 14:24:09 -04004// struct. In particular, this test exercises that the correct
Alan Donovan1f2812f2013-05-31 16:36:03 -04005// 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{}
Alan Donovan4da31df2013-07-26 11:22:34 -040029 if one := s.I.one(); one != 1 {
30 panic(one)
31 }
Alan Donovan1f2812f2013-05-31 16:36:03 -040032 if one := s.one(); one != 1 {
33 panic(one)
34 }
Alan Donovan4da31df2013-07-26 11:22:34 -040035 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 }
Alan Donovan1f2812f2013-05-31 16:36:03 -040047 if two := s.two(); two != "two" {
48 panic(two)
49 }
Alan Donovan4da31df2013-07-26 11:22:34 -040050 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 }
Alan Donovan1f2812f2013-05-31 16:36:03 -040058}