2013-05-31 14:36:03 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
// Test of promotion of methods of an interface embedded within a
|
2013-07-29 12:24:09 -06:00
|
|
|
// struct. In particular, this test exercises that the correct
|
2013-05-31 14:36:03 -06:00
|
|
|
// method is called.
|
|
|
|
|
|
|
|
type I interface {
|
|
|
|
one() int
|
|
|
|
two() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type S struct {
|
|
|
|
I
|
|
|
|
}
|
|
|
|
|
|
|
|
type impl struct{}
|
|
|
|
|
|
|
|
func (impl) one() int {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (impl) two() string {
|
|
|
|
return "two"
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var s S
|
|
|
|
s.I = impl{}
|
2013-07-26 09:22:34 -06:00
|
|
|
if one := s.I.one(); one != 1 {
|
|
|
|
panic(one)
|
|
|
|
}
|
2013-05-31 14:36:03 -06:00
|
|
|
if one := s.one(); one != 1 {
|
|
|
|
panic(one)
|
|
|
|
}
|
2013-07-26 09:22:34 -06:00
|
|
|
closOne := s.I.one
|
|
|
|
if one := closOne(); one != 1 {
|
|
|
|
panic(one)
|
|
|
|
}
|
|
|
|
closOne = s.one
|
|
|
|
if one := closOne(); one != 1 {
|
|
|
|
panic(one)
|
|
|
|
}
|
|
|
|
|
|
|
|
if two := s.I.two(); two != "two" {
|
|
|
|
panic(two)
|
|
|
|
}
|
2013-05-31 14:36:03 -06:00
|
|
|
if two := s.two(); two != "two" {
|
|
|
|
panic(two)
|
|
|
|
}
|
2013-07-26 09:22:34 -06:00
|
|
|
closTwo := s.I.two
|
|
|
|
if two := closTwo(); two != "two" {
|
|
|
|
panic(two)
|
|
|
|
}
|
|
|
|
closTwo = s.two
|
|
|
|
if two := closTwo(); two != "two" {
|
|
|
|
panic(two)
|
|
|
|
}
|
2013-05-31 14:36:03 -06:00
|
|
|
}
|