package typeparams
import "golang.org/x/tools/internal/typeparams"
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 ForFuncType(*ast.FuncType) *ast.FieldList
- func ForTypeSpec(*ast.TypeSpec) *ast.FieldList
- func InitInstanceInfo(*types.Info)
- func Instantiate(env *Environment, typ types.Type, targs []types.Type, validate bool) (types.Type, error)
- func IsComparable(*types.Interface) bool
- func IsConstraint(*types.Interface) bool
- func NamedTypeOrigin(named *types.Named) types.Type
- func SetForNamed(_ *types.Named, tparams []*TypeParam)
- func SetForSignature(_ *types.Signature, tparams []*TypeParam)
- func SetRecvTypeParams(sig *types.Signature, rparams []*TypeParam)
- func SetTypeParamConstraint(tparam *TypeParam, constraint types.Type)
- type Environment
- type IndexExprData
- type Term
- func NewTerm(tilde bool, typ types.Type) *Term
- func (*Term) String() string
- func (*Term) Tilde() bool
- func (*Term) Type() types.Type
- func (*Term) Underlying() types.Type
- type TypeList
- func GetInstance(*types.Info, *ast.Ident) (*TypeList, types.Type)
- func NamedTypeArgs(*types.Named) *TypeList
- func (*TypeList) At(int) types.Type
- func (*TypeList) Len() int
- type TypeParam
- func NewTypeParam(name *types.TypeName, constraint types.Type) *TypeParam
- func (*TypeParam) Constraint() types.Type
- func (*TypeParam) Obj() *types.TypeName
- type TypeParamList
- func ForNamed(*types.Named) *TypeParamList
- func ForSignature(*types.Signature) *TypeParamList
- func RecvTypeParams(sig *types.Signature) *TypeParamList
- func (*TypeParamList) At(int) *TypeParam
- func (*TypeParamList) Len() int
- type Union
Constants ¶
const Enabled = false
Enabled reports whether type parameters are enabled in the current build environment.
Functions ¶
func ForFuncType ¶
ForFuncType returns an empty field list, as type parameters are not supported at this Go version.
func ForTypeSpec ¶
ForTypeSpec returns an empty field list, as type parameters on not supported at this Go version.
func InitInstanceInfo ¶
InitInstanceInfo is a noop at this Go version.
func Instantiate ¶
func Instantiate(env *Environment, typ types.Type, targs []types.Type, validate bool) (types.Type, error)
Instantiate is unsupported on this Go version, and panics.
func IsComparable ¶
IsComparable returns false, as no interfaces are type-restricted at this Go version.
func IsConstraint ¶
IsConstraint returns false, as no interfaces are type-restricted at this Go version.
func NamedTypeOrigin ¶
NamedTypeOrigin is the identity method at this Go version.
func SetForNamed ¶
SetForNamed panics if tparams is non-empty.
func SetForSignature ¶
SetForSignature panics if tparams is non-empty.
func SetRecvTypeParams ¶
SetRecvTypeParams panics if rparams is non-empty.
func SetTypeParamConstraint ¶
SetTypeParamConstraint is unsupported at this Go version, and panics.
Types ¶
type Environment ¶
type Environment struct{}
Environment is a placeholder type, as type parameters are not supported at this Go version.
type IndexExprData ¶
type IndexExprData struct { X ast.Expr // expression Lbrack token.Pos // position of "[" Indices []ast.Expr // index expressions Rbrack token.Pos // position of "]" }
A IndexExprData holds data from both ast.IndexExpr and the new ast.MultiIndexExpr, which was introduced in Go 1.18.
func GetIndexExprData ¶
func GetIndexExprData(n ast.Node) *IndexExprData
GetIndexExprData extracts data from *ast.IndexExpr nodes. For other nodes, GetIndexExprData returns nil.
type Term ¶
type Term struct{}
Term is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.
func NewTerm ¶
NewTerm is unsupported at this Go version, and panics.
func (*Term) String ¶
func (*Term) Tilde ¶
func (*Term) Type ¶
func (*Term) Underlying ¶
type TypeList ¶
type TypeList struct{}
TypeList is a placeholder for an empty type list.
func GetInstance ¶
GetInstance returns nothing, as type parameters are not supported at this Go version.
func NamedTypeArgs ¶
NamedTypeArgs returns nil.
func (*TypeList) At ¶
func (*TypeList) Len ¶
type TypeParam ¶
TypeParam is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.
func NewTypeParam ¶
NewTypeParam is unsupported at this Go version, and panics.
func (*TypeParam) Constraint ¶
func (*TypeParam) Obj ¶
type TypeParamList ¶
type TypeParamList struct{}
TypeParamList is a placeholder for an empty type parameter list.
func ForNamed ¶
func ForNamed(*types.Named) *TypeParamList
ForNamed returns an empty type parameter list, as type parameters are not supported at this Go version.
func ForSignature ¶
func ForSignature(*types.Signature) *TypeParamList
ForSignature returns an empty slice.
func RecvTypeParams ¶
func RecvTypeParams(sig *types.Signature) *TypeParamList
RecvTypeParams returns a nil slice.
func (*TypeParamList) At ¶
func (*TypeParamList) At(int) *TypeParam
func (*TypeParamList) Len ¶
func (*TypeParamList) Len() int
type Union ¶
Union is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.
func NewUnion ¶
NewUnion is unsupported at this Go version, and panics.
func (*Union) Len ¶
func (*Union) Term ¶
Source Files ¶
common.go enabled_go117.go typeparams_go117.go
- Version
- v0.1.7
- Published
- Sep 28, 2021
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 17 minutes ago –
Tools for package owners.