github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types2/lookup.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file implements various field and method lookup functions.
     6  
     7  package types2
     8  
     9  // LookupFieldOrMethod looks up a field or method with given package and name
    10  // in T and returns the corresponding *Var or *Func, an index sequence, and a
    11  // bool indicating if there were any pointer indirections on the path to the
    12  // field or method. If addressable is set, T is the type of an addressable
    13  // variable (only matters for method lookups). T must not be nil.
    14  //
    15  // The last index entry is the field or method index in the (possibly embedded)
    16  // type where the entry was found, either:
    17  //
    18  //  1. the list of declared methods of a named type; or
    19  //  2. the list of all methods (method set) of an interface type; or
    20  //  3. the list of fields of a struct type.
    21  //
    22  // The earlier index entries are the indices of the embedded struct fields
    23  // traversed to get to the found entry, starting at depth 0.
    24  //
    25  // If no entry is found, a nil object is returned. In this case, the returned
    26  // index and indirect values have the following meaning:
    27  //
    28  //   - If index != nil, the index sequence points to an ambiguous entry
    29  //     (the same name appeared more than once at the same embedding level).
    30  //
    31  //   - If indirect is set, a method with a pointer receiver type was found
    32  //     but there was no pointer on the path from the actual receiver type to
    33  //     the method's formal receiver base type, nor was the receiver addressable.
    34  func LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool)
    35  
    36  // MissingMethod returns (nil, false) if V implements T, otherwise it
    37  // returns a missing method required by T and whether it is missing or
    38  // just has the wrong type: either a pointer receiver or wrong signature.
    39  //
    40  // For non-interface types V, or if static is set, V implements T if all
    41  // methods of T are present in V. Otherwise (V is an interface and static
    42  // is not set), MissingMethod only checks that methods of T which are also
    43  // present in V have matching types (e.g., for a type assertion x.(T) where
    44  // x is of interface type V).
    45  func MissingMethod(V Type, T *Interface, static bool) (method *Func, wrongType bool)