go.tools/go/types: handle embedded interfaces in NewInterface

R=gri
CC=golang-dev
https://golang.org/cl/39040043
This commit is contained in:
Peter Collingbourne 2013-12-09 13:37:24 -08:00 committed by Robert Griesemer
parent fb3d862cae
commit 7dcd8ded7c
1 changed files with 21 additions and 3 deletions

View File

@ -273,11 +273,29 @@ func NewInterface(methods []*Func, types []*Named) *Interface {
}
sort.Sort(byUniqueMethodName(methods))
if types != nil {
panic("unimplemented")
var allMethods []*Func
if types == nil {
allMethods = methods
} else {
allMethods = append(allMethods, methods...)
for _, t := range types {
it := t.Underlying().(*Interface)
for _, tm := range it.allMethods {
// Make a copy of the method and adjust its receiver type.
newm := *tm
newmtyp := *tm.typ.(*Signature)
newm.typ = &newmtyp
newmtyp.recv = NewVar(newm.pos, newm.pkg, "", typ)
allMethods = append(allMethods, &newm)
}
}
sort.Sort(byUniqueMethodName(allMethods))
}
return &Interface{methods: methods, allMethods: methods}
typ.methods = methods
typ.types = types
typ.allMethods = allMethods
return typ
}
// NumMethods returns the number of methods of interface t.