5 // lookupMethod returns the index of and method with matching package and name, or (-1, nil).
6 func lookupMethod(T *types.Interface, pkg *types.Package, name string) (int, *types.Func) {
8 for i := 0; i < T.NumMethods(); i++ {
10 if sameId(m, pkg, name) {
18 func sameId(obj types.Object, pkg *types.Package, name string) bool {
20 // "Two identifiers are different if they are spelled differently,
21 // or if they appear in different packages and are not exported.
22 // Otherwise, they are the same."
23 if name != obj.Name() {
30 // not exported, so packages must be the same (pkg == nil for
31 // fields in Universe scope; this can only happen for types
32 // introduced via Eval)
33 if pkg == nil || obj.Pkg() == nil {
34 return pkg == obj.Pkg()
36 // pkg != nil && obj.pkg != nil
37 return pkg.Path() == obj.Pkg().Path()
40 func (g *Graph) implements(V types.Type, T *types.Interface, msV *types.MethodSet) ([]*types.Selection, bool) {
41 // fast path for common case
46 if ityp, _ := V.Underlying().(*types.Interface); ityp != nil {
47 // TODO(dh): is this code reachable?
48 for i := 0; i < T.NumMethods(); i++ {
50 _, obj := lookupMethod(ityp, m.Pkg(), m.Name())
54 case !types.Identical(obj.Type(), m.Type()):
61 // A concrete type implements T if it implements all methods of T.
62 var sels []*types.Selection
63 for i := 0; i < T.NumMethods(); i++ {
65 sel := msV.Lookup(m.Pkg(), m.Name())
70 f, _ := sel.Obj().(*types.Func)
75 if !types.Identical(f.Type(), m.Type()) {
79 sels = append(sels, sel)