Documentation ¶
Overview ¶
Package typeparams provides functions to work indirectly with type parameter data stored in go/ast and go/types objects, while these API are guarded by a build constraint.
This package exists to make it easier for tools to work with generic code, while also compiling against older Go versions.
Index ¶
- Constants
- func ForFuncDecl(*ast.FuncDecl) *ast.FieldList
- func ForNamed(*types.Named) []*types.TypeName
- func ForSignature(*types.Signature) []*types.TypeName
- func ForTypeDecl(*ast.TypeSpec) *ast.FieldList
- func GetInferred(*types.Info, ast.Expr) ([]types.Type, *types.Signature)
- func HasTypeSet(*types.Interface) bool
- func InitInferred(*types.Info)
- func IsComparable(*types.Interface) bool
- func IsConstraint(*types.Interface) bool
- func IsListExpr(n ast.Node) bool
- func NamedTArgs(*types.Named) []types.Type
- func UnpackIndex(e *ast.IndexExpr) []ast.Expr
Constants ¶
const Enabled = false
Enabled reports whether type parameters are enabled in the current build environment.
Variables ¶
This section is empty.
Functions ¶
func ForFuncDecl ¶
ForFuncDecl extracts the (possibly nil) type parameter node list from n.
func ForSignature ¶
ForSignature extracts the (possibly empty) type parameter object list from sig.
func ForTypeDecl ¶
ForTypeDecl extracts the (possibly nil) type parameter node list from n.
func GetInferred ¶
GetInferred extracts inferred type information from info for e.
The expression e may have an inferred type if it is an *ast.IndexExpr representing partial instantiation of a generic function type for which type arguments have been inferred using constraint type inference, or if it is an *ast.CallExpr for which type type arguments have be inferred using both constraint type inference and function argument inference.
func HasTypeSet ¶
HasTypeSet reports if iface has a type set.
func InitInferred ¶
InitInferred initializes info to record inferred type information.
func IsComparable ¶
IsComparable reports if iface is the comparable interface.
func IsConstraint ¶
IsConstraint reports whether iface may only be used as a type parameter constraint (i.e. has a type set or is the comparable interface).
func IsListExpr ¶
IsListExpr reports whether n is an *ast.ListExpr, which is a new node type introduced to hold type arguments for generic type instantiation.
func NamedTArgs ¶
NamedTArgs extracts the (possibly empty) type argument list from named.
Types ¶
This section is empty.