mirror of
https://github.com/golang/go
synced 2024-11-19 08:04:40 -07:00
fb0642f5fb
buildDecl was visiting all decls in source order, but the spec calls for visiting all vars and init() funcs in order, then all remaining functions. These two passes are now called buildInit(), buildFuncDecl(). + Test. Also: - Added workaround to gcimporter for Func with pkg==nil. - Prog.concreteMethods has been merged into Pkg.values. - Prog.concreteMethod() renamed declaredFunc(). - s/mfunc/obj/ (name cleanup from recent gri CL) R=gri CC=golang-dev https://golang.org/cl/12030044
59 lines
854 B
Go
59 lines
854 B
Go
package main
|
|
|
|
// Test of promotion of methods of an interface embedded within a
|
|
// struct. In particular, this test exercises that the correct
|
|
// 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{}
|
|
if one := s.I.one(); one != 1 {
|
|
panic(one)
|
|
}
|
|
if one := s.one(); one != 1 {
|
|
panic(one)
|
|
}
|
|
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)
|
|
}
|
|
if two := s.two(); two != "two" {
|
|
panic(two)
|
|
}
|
|
closTwo := s.I.two
|
|
if two := closTwo(); two != "two" {
|
|
panic(two)
|
|
}
|
|
closTwo = s.two
|
|
if two := closTwo(); two != "two" {
|
|
panic(two)
|
|
}
|
|
}
|