type Named … type instance … type namedState … const unresolved … const resolved … const complete … // NewNamed returns a new named type for the given type name, underlying type, and associated methods. // If the given type name obj doesn't have a type yet, its type is set to the returned named type. // The underlying type must not be a *Named. func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named { … } // resolve resolves the type parameters, methods, and underlying type of n. // This information may be loaded from a provided loader function, or computed // from an origin type (in the case of instances). // // After resolution, the type parameters, methods, and underlying type of n are // accessible; but if n is an instantiated type, its methods may still be // unexpanded. func (n *Named) resolve() *Named { … } // state atomically accesses the current state of the receiver. func (n *Named) state() namedState { … } // setState atomically stores the given state for n. // Must only be called while holding n.mu. func (n *Named) setState(state namedState) { … } // newNamed is like NewNamed but with a *Checker receiver. func (check *Checker) newNamed(obj *TypeName, underlying Type, methods []*Func) *Named { … } // newNamedInstance creates a new named instance for the given origin and type // arguments, recording pos as the position of its synthetic object (for error // reporting). // // If set, expanding is the named type instance currently being expanded, that // led to the creation of this instance. func (check *Checker) newNamedInstance(pos syntax.Pos, orig *Named, targs []Type, expanding *Named) *Named { … } func (t *Named) cleanup() { … } // Obj returns the type name for the declaration defining the named type t. For // instantiated types, this is same as the type name of the origin type. func (t *Named) Obj() *TypeName { … } // Origin returns the generic type from which the named type t is // instantiated. If t is not an instantiated type, the result is t. func (t *Named) Origin() *Named { … } // TypeParams returns the type parameters of the named type t, or nil. // The result is non-nil for an (originally) generic type even if it is instantiated. func (t *Named) TypeParams() *TypeParamList { … } // SetTypeParams sets the type parameters of the named type t. // t must not have type arguments. func (t *Named) SetTypeParams(tparams []*TypeParam) { … } // TypeArgs returns the type arguments used to instantiate the named type t. func (t *Named) TypeArgs() *TypeList { … } // NumMethods returns the number of explicit methods defined for t. func (t *Named) NumMethods() int { … } // Method returns the i'th method of named type t for 0 <= i < t.NumMethods(). // // For an ordinary or instantiated type t, the receiver base type of this // method is the named type t. For an uninstantiated generic type t, each // method receiver is instantiated with its receiver type parameters. // // Methods are numbered deterministically: given the same list of source files // presented to the type checker, or the same sequence of NewMethod and AddMethod // calls, the mapping from method index to corresponding method remains the same. // But the specific ordering is not specified and must not be relied on as it may // change in the future. func (t *Named) Method(i int) *Func { … } // expandMethod substitutes type arguments in the i'th method for an // instantiated receiver. func (t *Named) expandMethod(i int) *Func { … } // SetUnderlying sets the underlying type and marks t as complete. // t must not have type arguments. func (t *Named) SetUnderlying(underlying Type) { … } // AddMethod adds method m unless it is already in the method list. // The method must be in the same package as t, and t must not have // type arguments. func (t *Named) AddMethod(m *Func) { … } // methodIndex returns the index of the method with the given name. // If foldCase is set, capitalization in the name is ignored. // The result is negative if no such method exists. func (t *Named) methodIndex(name string, foldCase bool) int { … } // Underlying returns the [underlying type] of the named type t, resolving all // forwarding declarations. Underlying types are never Named, TypeParam, or // Alias types. // // [underlying type]: https://go.dev/ref/spec#Underlying_types. func (t *Named) Underlying() Type { … } func (t *Named) String() string { … } // under returns the expanded underlying type of n0; possibly by following // forward chains of named types. If an underlying type is found, resolve // the chain by setting the underlying type for each defined type in the // chain before returning it. If no underlying type is found or a cycle // is detected, the result is Typ[Invalid]. If a cycle is detected and // n0.check != nil, the cycle is reported. // // This is necessary because the underlying type of named may be itself a // named type that is incomplete: // // type ( // A B // B *C // C A // ) // // The type of C is the (named) type of A which is incomplete, // and which has as its underlying type the named type B. func (n0 *Named) under() Type { … } func (n *Named) lookupMethod(pkg *Package, name string, foldCase bool) (int, *Func) { … } // context returns the type-checker context. func (check *Checker) context() *Context { … } // expandUnderlying substitutes type arguments in the underlying type n.orig, // returning the result. Returns Typ[Invalid] if there was an error. func (n *Named) expandUnderlying() Type { … } // safeUnderlying returns the underlying type of typ without expanding // instances, to avoid infinite recursion. // // TODO(rfindley): eliminate this function or give it a better name. func safeUnderlying(typ Type) Type { … }