From 7dcd8ded7cc178ba4a3ed71fcd7e92b89cb7291a Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 9 Dec 2013 13:37:24 -0800 Subject: [PATCH] go.tools/go/types: handle embedded interfaces in NewInterface R=gri CC=golang-dev https://golang.org/cl/39040043 --- go/types/types.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/go/types/types.go b/go/types/types.go index b8190c49..3272f2fc 100644 --- a/go/types/types.go +++ b/go/types/types.go @@ -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.