]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/types/lookup.go
go/types, types2: introduce _Alias type node
[gostls13.git] / src / go / types / lookup.go
index a270159499d8cd6cb02e919d409799b7708590ab..e6ad72843743ab2a856006e36bedf34904cb1fbf 100644 (file)
@@ -1,3 +1,5 @@
+// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
+
 // Copyright 2013 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
@@ -6,6 +8,12 @@
 
 package types
 
+import (
+       "bytes"
+       "go/token"
+       "strings"
+)
+
 // Internal use of LookupFieldOrMethod: If the obj result is a method
 // associated with a concrete (non-interface) type, the method's signature
 // may not be fully set up. Call Checker.objDecl(obj, nil) before accessing
@@ -15,14 +23,14 @@ package types
 // in T and returns the corresponding *Var or *Func, an index sequence, and a
 // bool indicating if there were any pointer indirections on the path to the
 // field or method. If addressable is set, T is the type of an addressable
-// variable (only matters for method lookups).
+// variable (only matters for method lookups). T must not be nil.
 //
 // The last index entry is the field or method index in the (possibly embedded)
 // type where the entry was found, either:
 //
-//     1) the list of declared methods of a named type; or
-//     2) the list of all methods (method set) of an interface type; or
-//     3) the list of fields of a struct type.
+//  1. the list of declared methods of a named type; or
+//  2. the list of all methods (method set) of an interface type; or
+//  3. the list of fields of a struct type.
 //
 // The earlier index entries are the indices of the embedded struct fields
 // traversed to get to the found entry, starting at depth 0.
@@ -30,24 +38,27 @@ package types
 // If no entry is found, a nil object is returned. In this case, the returned
 // index and indirect values have the following meaning:
 //
-//     - If index != nil, the index sequence points to an ambiguous entry
-//     (the same name appeared more than once at the same embedding level).
-//
-//     - If indirect is set, a method with a pointer receiver type was found
-//      but there was no pointer on the path from the actual receiver type to
-//     the method's formal receiver base type, nor was the receiver addressable.
+//   - If index != nil, the index sequence points to an ambiguous entry
+//     (the same name appeared more than once at the same embedding level).
 //
+//   - If indirect is set, a method with a pointer receiver type was found
+//     but there was no pointer on the path from the actual receiver type to
+//     the method's formal receiver base type, nor was the receiver addressable.
 func LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) {
-       // Methods cannot be associated to a named pointer type
+       if T == nil {
+               panic("LookupFieldOrMethod on nil type")
+       }
+
+       // Methods cannot be associated to a named pointer type.
        // (spec: "The type denoted by T is called the receiver base type;
        // it must not be a pointer or interface type and it must be declared
        // in the same package as the method.").
        // Thus, if we have a named pointer type, proceed with the underlying
        // pointer type but discard the result if it is a method since we would
-       // not have found it for T (see also issue 8590).
+       // not have found it for T (see also go.dev/issue/8590).
        if t := asNamed(T); t != nil {
-               if p, _ := safeUnderlying(t).(*Pointer); p != nil {
-                       obj, index, indirect = lookupFieldOrMethod(p, false, pkg, name)
+               if p, _ := t.Underlying().(*Pointer); p != nil {
+                       obj, index, indirect = lookupFieldOrMethodImpl(p, false, pkg, name, false)
                        if _, ok := obj.(*Func); ok {
                                return nil, nil, false
                        }
@@ -55,30 +66,55 @@ func LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
                }
        }
 
-       return lookupFieldOrMethod(T, addressable, pkg, name)
+       obj, index, indirect = lookupFieldOrMethodImpl(T, addressable, pkg, name, false)
+
+       // If we didn't find anything and if we have a type parameter with a core type,
+       // see if there is a matching field (but not a method, those need to be declared
+       // explicitly in the constraint). If the constraint is a named pointer type (see
+       // above), we are ok here because only fields are accepted as results.
+       const enableTParamFieldLookup = false // see go.dev/issue/51576
+       if enableTParamFieldLookup && obj == nil && isTypeParam(T) {
+               if t := coreType(T); t != nil {
+                       obj, index, indirect = lookupFieldOrMethodImpl(t, addressable, pkg, name, false)
+                       if _, ok := obj.(*Var); !ok {
+                               obj, index, indirect = nil, nil, false // accept fields (variables) only
+                       }
+               }
+       }
+       return
 }
 
-// TODO(gri) The named type consolidation and seen maps below must be
-//           indexed by unique keys for a given type. Verify that named
-//           types always have only one representation (even when imported
-//           indirectly via different packages.)
-
-// lookupFieldOrMethod should only be called by LookupFieldOrMethod and missingMethod.
-func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) {
+// lookupFieldOrMethodImpl is the implementation of LookupFieldOrMethod.
+// Notably, in contrast to LookupFieldOrMethod, it won't find struct fields
+// in base types of defined (*Named) pointer types T. For instance, given
+// the declaration:
+//
+//     type T *struct{f int}
+//
+// lookupFieldOrMethodImpl won't find the field f in the defined (*Named) type T
+// (methods on T are not permitted in the first place).
+//
+// Thus, lookupFieldOrMethodImpl should only be called by LookupFieldOrMethod
+// and missingMethod (the latter doesn't care about struct fields).
+//
+// If foldCase is true, method names are considered equal if they are equal
+// with case folding.
+//
+// The resulting object may not be fully type-checked.
+func lookupFieldOrMethodImpl(T Type, addressable bool, pkg *Package, name string, foldCase bool) (obj Object, index []int, indirect bool) {
        // WARNING: The code in this function is extremely subtle - do not modify casually!
 
        if name == "_" {
                return // blank fields/methods are never found
        }
 
+       // Importantly, we must not call under before the call to deref below (nor
+       // does deref call under), as doing so could incorrectly result in finding
+       // methods of the pointer base type when T is a (*Named) pointer type.
        typ, isPtr := deref(T)
 
-       // *typ where typ is an interface or type parameter has no methods.
+       // *typ where typ is an interface (incl. a type parameter) has no methods.
        if isPtr {
-               // don't look at under(typ) here - was bug (issue #47747)
-               if _, ok := typ.(*TypeParam); ok {
-                       return
-               }
                if _, ok := under(typ).(*Interface); ok {
                        return
                }
@@ -87,28 +123,25 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
        // Start with typ as single entry at shallowest depth.
        current := []embeddedType{{typ, nil, isPtr, false}}
 
-       // Named types that we have seen already, allocated lazily.
+       // seen tracks named types that we have seen already, allocated lazily.
        // Used to avoid endless searches in case of recursive types.
-       // Since only Named types can be used for recursive types, we
-       // only need to track those.
-       // (If we ever allow type aliases to construct recursive types,
-       // we must use type identity rather than pointer equality for
-       // the map key comparison, as we do in consolidateMultiples.)
-       var seen map[*Named]bool
+       //
+       // We must use a lookup on identity rather than a simple map[*Named]bool as
+       // instantiated types may be identical but not equal.
+       var seen instanceLookup
 
        // search current depth
        for len(current) > 0 {
                var next []embeddedType // embedded types found at current depth
 
                // look for (pkg, name) in all types at current depth
-               var tpar *TypeParam // set if obj receiver is a type parameter
                for _, e := range current {
                        typ := e.typ
 
                        // If we have a named type, we may have associated methods.
                        // Look for those first.
                        if named := asNamed(typ); named != nil {
-                               if seen[named] {
+                               if alt := seen.lookup(named); alt != nil {
                                        // We have seen this type before, at a more shallow depth
                                        // (note that multiples of this type at the current depth
                                        // were consolidated before). The type at that depth shadows
@@ -116,14 +149,10 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
                                        // this one.
                                        continue
                                }
-                               if seen == nil {
-                                       seen = make(map[*Named]bool)
-                               }
-                               seen[named] = true
+                               seen.add(named)
 
                                // look for a matching attached method
-                               named.resolve(nil)
-                               if i, m := lookupMethod(named.methods, pkg, name); m != nil {
+                               if i, m := named.lookupMethod(pkg, name, foldCase); m != nil {
                                        // potential match
                                        // caution: method may not have a proper signature yet
                                        index = concat(e.index, i)
@@ -134,19 +163,9 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
                                        indirect = e.indirect
                                        continue // we can't have a matching field or interface method
                                }
-
-                               // continue with underlying type, but only if it's not a type parameter
-                               // TODO(gri) is this what we want to do for type parameters? (spec question)
-                               // TODO(#45639) the error message produced as a result of skipping an
-                               //              underlying type parameter should be improved.
-                               typ = named.under()
-                               if asTypeParam(typ) != nil {
-                                       continue
-                               }
                        }
 
-                       tpar = nil
-                       switch t := typ.(type) {
+                       switch t := under(typ).(type) {
                        case *Struct:
                                // look for a matching field and collect embedded types
                                for i, f := range t.fields {
@@ -179,8 +198,8 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
                                }
 
                        case *Interface:
-                               // look for a matching method
-                               if i, m := t.typeSet().LookupMethod(pkg, name); m != nil {
+                               // look for a matching method (interface may be a type parameter)
+                               if i, m := t.typeSet().LookupMethod(pkg, name, foldCase); m != nil {
                                        assert(m.typ != nil)
                                        index = concat(e.index, i)
                                        if obj != nil || e.multiples {
@@ -189,18 +208,6 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
                                        obj = m
                                        indirect = e.indirect
                                }
-
-                       case *TypeParam:
-                               if i, m := t.iface().typeSet().LookupMethod(pkg, name); m != nil {
-                                       assert(m.typ != nil)
-                                       index = concat(e.index, i)
-                                       if obj != nil || e.multiples {
-                                               return nil, index, false // collision
-                                       }
-                                       tpar = t
-                                       obj = m
-                                       indirect = e.indirect
-                               }
                        }
                }
 
@@ -212,8 +219,7 @@ func lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (o
                        //        is shorthand for (&x).m()".
                        if f, _ := obj.(*Func); f != nil {
                                // determine if method has a pointer receiver
-                               hasPtrRecv := tpar == nil && ptrRecv(f)
-                               if hasPtrRecv && !indirect && !addressable {
+                               if f.hasPtrRecv() && !indirect && !addressable {
                                        return nil, nil, true // pointer/addressable receiver required
                                }
                        }
@@ -272,144 +278,265 @@ func lookupType(m map[Type]int, typ Type) (int, bool) {
        return 0, false
 }
 
+type instanceLookup struct {
+       // buf is used to avoid allocating the map m in the common case of a small
+       // number of instances.
+       buf [3]*Named
+       m   map[*Named][]*Named
+}
+
+func (l *instanceLookup) lookup(inst *Named) *Named {
+       for _, t := range l.buf {
+               if t != nil && Identical(inst, t) {
+                       return t
+               }
+       }
+       for _, t := range l.m[inst.Origin()] {
+               if Identical(inst, t) {
+                       return t
+               }
+       }
+       return nil
+}
+
+func (l *instanceLookup) add(inst *Named) {
+       for i, t := range l.buf {
+               if t == nil {
+                       l.buf[i] = inst
+                       return
+               }
+       }
+       if l.m == nil {
+               l.m = make(map[*Named][]*Named)
+       }
+       insts := l.m[inst.Origin()]
+       l.m[inst.Origin()] = append(insts, inst)
+}
+
 // MissingMethod returns (nil, false) if V implements T, otherwise it
 // returns a missing method required by T and whether it is missing or
-// just has the wrong type.
+// just has the wrong type: either a pointer receiver or wrong signature.
 //
 // For non-interface types V, or if static is set, V implements T if all
 // methods of T are present in V. Otherwise (V is an interface and static
 // is not set), MissingMethod only checks that methods of T which are also
 // present in V have matching types (e.g., for a type assertion x.(T) where
 // x is of interface type V).
-//
 func MissingMethod(V Type, T *Interface, static bool) (method *Func, wrongType bool) {
-       m, typ := (*Checker)(nil).missingMethod(V, T, static)
-       return m, typ != nil
+       return (*Checker)(nil).missingMethod(V, T, static, Identical, nil)
 }
 
-// missingMethod is like MissingMethod but accepts a *Checker as
-// receiver and an addressable flag.
-// The receiver may be nil if missingMethod is invoked through
-// an exported API call (such as MissingMethod), i.e., when all
-// methods have been type-checked.
-// If the type has the correctly named method, but with the wrong
-// signature, the existing method is returned as well.
-// To improve error messages, also report the wrong signature
-// when the method exists on *V instead of V.
-func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method, wrongType *Func) {
-       // fast path for common case
-       if T.Empty() {
-               return
+// missingMethod is like MissingMethod but accepts a *Checker as receiver,
+// a comparator equivalent for type comparison, and a *string for error causes.
+// The receiver may be nil if missingMethod is invoked through an exported
+// API call (such as MissingMethod), i.e., when all methods have been type-
+// checked.
+// The underlying type of T must be an interface; T (rather than its under-
+// lying type) is used for better error messages (reported through *cause).
+// The comparator is used to compare signatures.
+// If a method is missing and cause is not nil, *cause describes the error.
+func (check *Checker) missingMethod(V, T Type, static bool, equivalent func(x, y Type) bool, cause *string) (method *Func, wrongType bool) {
+       methods := under(T).(*Interface).typeSet().methods // T must be an interface
+       if len(methods) == 0 {
+               return nil, false
        }
 
-       if ityp := asInterface(V); ityp != nil {
-               // TODO(gri) the methods are sorted - could do this more efficiently
-               for _, m := range T.typeSet().methods {
-                       _, f := ityp.typeSet().LookupMethod(m.pkg, m.name)
+       const (
+               ok = iota
+               notFound
+               wrongName
+               wrongSig
+               ambigSel
+               ptrRecv
+               field
+       )
+
+       state := ok
+       var m *Func // method on T we're trying to implement
+       var f *Func // method on V, if found (state is one of ok, wrongName, wrongSig)
+
+       if u, _ := under(V).(*Interface); u != nil {
+               tset := u.typeSet()
+               for _, m = range methods {
+                       _, f = tset.LookupMethod(m.pkg, m.name, false)
 
                        if f == nil {
                                if !static {
                                        continue
                                }
-                               return m, f
+                               state = notFound
+                               break
                        }
 
-                       // both methods must have the same number of type parameters
-                       ftyp := f.typ.(*Signature)
-                       mtyp := m.typ.(*Signature)
-                       if ftyp.TypeParams().Len() != mtyp.TypeParams().Len() {
-                               return m, f
+                       if !equivalent(f.typ, m.typ) {
+                               state = wrongSig
+                               break
                        }
-                       if ftyp.TypeParams().Len() > 0 {
-                               panic("method with type parameters")
+               }
+       } else {
+               for _, m = range methods {
+                       obj, index, indirect := lookupFieldOrMethodImpl(V, false, m.pkg, m.name, false)
+
+                       // check if m is ambiguous, on *V, or on V with case-folding
+                       if obj == nil {
+                               switch {
+                               case index != nil:
+                                       state = ambigSel
+                               case indirect:
+                                       state = ptrRecv
+                               default:
+                                       state = notFound
+                                       obj, _, _ = lookupFieldOrMethodImpl(V, false, m.pkg, m.name, true /* fold case */)
+                                       f, _ = obj.(*Func)
+                                       if f != nil {
+                                               state = wrongName
+                                       }
+                               }
+                               break
                        }
 
-                       // If the methods have type parameters we don't care whether they
-                       // are the same or not, as long as they match up. Use unification
-                       // to see if they can be made to match.
-                       // TODO(gri) is this always correct? what about type bounds?
-                       // (Alternative is to rename/subst type parameters and compare.)
-                       u := newUnifier(true)
-                       u.x.init(ftyp.TypeParams().list())
-                       if !u.unify(ftyp, mtyp) {
-                               return m, f
+                       // we must have a method (not a struct field)
+                       f, _ = obj.(*Func)
+                       if f == nil {
+                               state = field
+                               break
+                       }
+
+                       // methods may not have a fully set up signature yet
+                       if check != nil {
+                               check.objDecl(f, nil)
+                       }
+
+                       if !equivalent(f.typ, m.typ) {
+                               state = wrongSig
+                               break
                        }
                }
+       }
 
-               return
+       if state == ok {
+               return nil, false
        }
 
-       // A concrete type implements T if it implements all methods of T.
-       for _, m := range T.typeSet().methods {
-               // TODO(gri) should this be calling lookupFieldOrMethod instead (and why not)?
-               obj, _, _ := lookupFieldOrMethod(V, false, m.pkg, m.name)
-
-               // Check if *V implements this method of T.
-               if obj == nil {
-                       ptr := NewPointer(V)
-                       obj, _, _ = lookupFieldOrMethod(ptr, false, m.pkg, m.name)
-                       if obj != nil {
-                               return m, obj.(*Func)
+       if cause != nil {
+               if f != nil {
+                       // This method may be formatted in funcString below, so must have a fully
+                       // set up signature.
+                       if check != nil {
+                               check.objDecl(f, nil)
                        }
                }
-
-               // we must have a method (not a field of matching function type)
-               f, _ := obj.(*Func)
-               if f == nil {
-                       return m, nil
+               switch state {
+               case notFound:
+                       switch {
+                       case isInterfacePtr(V):
+                               *cause = "(" + check.interfacePtrError(V) + ")"
+                       case isInterfacePtr(T):
+                               *cause = "(" + check.interfacePtrError(T) + ")"
+                       default:
+                               *cause = check.sprintf("(missing method %s)", m.Name())
+                       }
+               case wrongName:
+                       fs, ms := check.funcString(f, false), check.funcString(m, false)
+                       *cause = check.sprintf("(missing method %s)\n\t\thave %s\n\t\twant %s",
+                               m.Name(), fs, ms)
+               case wrongSig:
+                       fs, ms := check.funcString(f, false), check.funcString(m, false)
+                       if fs == ms {
+                               // Don't report "want Foo, have Foo".
+                               // Add package information to disambiguate (go.dev/issue/54258).
+                               fs, ms = check.funcString(f, true), check.funcString(m, true)
+                       }
+                       *cause = check.sprintf("(wrong type for method %s)\n\t\thave %s\n\t\twant %s",
+                               m.Name(), fs, ms)
+               case ambigSel:
+                       *cause = check.sprintf("(ambiguous selector %s.%s)", V, m.Name())
+               case ptrRecv:
+                       *cause = check.sprintf("(method %s has pointer receiver)", m.Name())
+               case field:
+                       *cause = check.sprintf("(%s.%s is a field, not a method)", V, m.Name())
+               default:
+                       unreachable()
                }
+       }
 
-               // methods may not have a fully set up signature yet
-               if check != nil {
-                       check.objDecl(f, nil)
-               }
+       return m, state == wrongSig || state == ptrRecv
+}
 
-               // both methods must have the same number of type parameters
-               ftyp := f.typ.(*Signature)
-               mtyp := m.typ.(*Signature)
-               if ftyp.TypeParams().Len() != mtyp.TypeParams().Len() {
-                       return m, f
-               }
-               if ftyp.TypeParams().Len() > 0 {
-                       panic("method with type parameters")
-               }
+func isInterfacePtr(T Type) bool {
+       p, _ := under(T).(*Pointer)
+       return p != nil && IsInterface(p.base)
+}
 
-               // If the methods have type parameters we don't care whether they
-               // are the same or not, as long as they match up. Use unification
-               // to see if they can be made to match.
-               // TODO(gri) is this always correct? what about type bounds?
-               // (Alternative is to rename/subst type parameters and compare.)
-               u := newUnifier(true)
-               u.x.init(ftyp.RecvTypeParams().list())
-               if !u.unify(ftyp, mtyp) {
-                       return m, f
-               }
+// check may be nil.
+func (check *Checker) interfacePtrError(T Type) string {
+       assert(isInterfacePtr(T))
+       if p, _ := under(T).(*Pointer); isTypeParam(p.base) {
+               return check.sprintf("type %s is pointer to type parameter, not type parameter", T)
        }
+       return check.sprintf("type %s is pointer to interface, not interface", T)
+}
 
-       return
+// funcString returns a string of the form name + signature for f.
+// check may be nil.
+func (check *Checker) funcString(f *Func, pkgInfo bool) string {
+       buf := bytes.NewBufferString(f.name)
+       var qf Qualifier
+       if check != nil && !pkgInfo {
+               qf = check.qualifier
+       }
+       w := newTypeWriter(buf, qf)
+       w.pkgInfo = pkgInfo
+       w.paramNames = false
+       w.signature(f.typ.(*Signature))
+       return buf.String()
 }
 
 // assertableTo reports whether a value of type V can be asserted to have type T.
-// It returns (nil, false) as affirmative answer. Otherwise it returns a missing
-// method required by V and whether it is missing or just has the wrong type.
 // The receiver may be nil if assertableTo is invoked through an exported API call
 // (such as AssertableTo), i.e., when all methods have been type-checked.
-// If the global constant forceStrict is set, assertions that are known to fail
-// are not permitted.
-func (check *Checker) assertableTo(V *Interface, T Type) (method, wrongType *Func) {
+// The underlying type of V must be an interface.
+// If the result is false and cause is not nil, *cause describes the error.
+// TODO(gri) replace calls to this function with calls to newAssertableTo.
+func (check *Checker) assertableTo(V, T Type, cause *string) bool {
        // no static check is required if T is an interface
        // spec: "If T is an interface type, x.(T) asserts that the
        //        dynamic type of x implements the interface T."
-       if asInterface(T) != nil && !forceStrict {
-               return
+       if IsInterface(T) {
+               return true
        }
-       return check.missingMethod(T, V, false)
+       // TODO(gri) fix this for generalized interfaces
+       m, _ := check.missingMethod(T, V, false, Identical, cause)
+       return m == nil
 }
 
-// deref dereferences typ if it is a *Pointer and returns its base and true.
+// newAssertableTo reports whether a value of type V can be asserted to have type T.
+// It also implements behavior for interfaces that currently are only permitted
+// in constraint position (we have not yet defined that behavior in the spec).
+// The underlying type of V must be an interface.
+// If the result is false and cause is not nil, *cause is set to the error cause.
+func (check *Checker) newAssertableTo(pos token.Pos, V, T Type, cause *string) bool {
+       // no static check is required if T is an interface
+       // spec: "If T is an interface type, x.(T) asserts that the
+       //        dynamic type of x implements the interface T."
+       if IsInterface(T) {
+               return true
+       }
+       return check.implements(pos, T, V, false, cause)
+}
+
+// deref dereferences typ if it is a *Pointer (but not a *Named type
+// with an underlying pointer type!) and returns its base and true.
 // Otherwise it returns (typ, false).
 func deref(typ Type) (Type, bool) {
-       if p, _ := typ.(*Pointer); p != nil {
+       if p, _ := _Unalias(typ).(*Pointer); p != nil {
+               // p.base should never be nil, but be conservative
+               if p.base == nil {
+                       if debug {
+                               panic("pointer with nil base type (possibly due to an invalid cyclic declaration)")
+                       }
+                       return Typ[Invalid], true
+               }
                return p.base, true
        }
        return typ, false
@@ -418,8 +545,8 @@ func deref(typ Type) (Type, bool) {
 // derefStructPtr dereferences typ if it is a (named or unnamed) pointer to a
 // (named or unnamed) struct and returns its base. Otherwise it returns typ.
 func derefStructPtr(typ Type) Type {
-       if p := asPointer(typ); p != nil {
-               if asStruct(p.base) != nil {
+       if p, _ := under(typ).(*Pointer); p != nil {
+               if _, ok := under(p.base).(*Struct); ok {
                        return p.base
                }
        }
@@ -447,10 +574,11 @@ func fieldIndex(fields []*Var, pkg *Package, name string) int {
 }
 
 // lookupMethod returns the index of and method with matching package and name, or (-1, nil).
-func lookupMethod(methods []*Func, pkg *Package, name string) (int, *Func) {
+// If foldCase is true, method names are considered equal if they are equal with case folding.
+func lookupMethod(methods []*Func, pkg *Package, name string, foldCase bool) (int, *Func) {
        if name != "_" {
                for i, m := range methods {
-                       if m.sameId(pkg, name) {
+                       if (m.name == name || foldCase && strings.EqualFold(m.name, name)) && m.sameId(pkg, m.name) {
                                return i, m
                        }
                }