typeparams

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

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

View Source
const Enabled = false

Enabled reports whether type parameters are enabled in the current build environment.

Variables

This section is empty.

Functions

func ForFuncDecl

func ForFuncDecl(*ast.FuncDecl) *ast.FieldList

ForFuncDecl returns an empty field list, as type parameters are not supported at this Go version.

func ForTypeDecl

func ForTypeDecl(*ast.TypeSpec) *ast.FieldList

ForTypeDecl returns an empty field list, as type parameters on not supported at this Go version.

func GetInferred

func GetInferred(*types.Info, ast.Expr) ([]types.Type, *types.Signature)

GetInferred returns nothing, as type parameters are not supported at this Go version.

func InitInferred

func InitInferred(*types.Info)

InitInferred is a noop at this Go version.

func Instantiate added in v0.1.6

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

func IsComparable(*types.Interface) bool

IsComparable returns false, as no interfaces are type-restricted at this Go version.

func IsConstraint

func IsConstraint(*types.Interface) bool

IsConstraint returns false, as no interfaces are type-restricted at this Go version.

func NamedTypeArgs added in v0.1.6

func NamedTypeArgs(*types.Named) []types.Type

NamedTypeArgs extracts the (possibly empty) type argument list from named.

func SetForNamed added in v0.1.6

func SetForNamed(_ *types.Named, tparams []*TypeParam)

SetForNamed panics if tparams is non-empty.

func SetForSignature added in v0.1.6

func SetForSignature(_ *types.Signature, tparams []*TypeParam)

SetForSignature panics if tparams is non-empty.

func SetRecvTypeParams added in v0.1.6

func SetRecvTypeParams(sig *types.Signature, rparams []*TypeParam)

SetRecvTypeParams panics if rparams is non-empty.

func SetTypeParamConstraint added in v0.1.6

func SetTypeParamConstraint(tparam *TypeParam, constraint types.Type)

SetTypeParamConstraint is unsupported at this Go version, and panics.

Types

type Environment added in v0.1.6

type Environment struct{}

Environment is a placeholder type, as type parameters are not supported at this Go version.

type IndexExprData added in v0.1.6

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 added in v0.1.6

func GetIndexExprData(n ast.Node) *IndexExprData

GetIndexExprData extracts data from *ast.IndexExpr nodes. For other nodes, GetIndexExprData returns nil.

type Term added in v0.1.6

type Term struct{ types.Type }

Term is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.

func NewTerm added in v0.1.6

func NewTerm(tilde bool, typ types.Type) *Term

NewTerm is unsupported at this Go version, and panics.

type TypeList added in v0.1.6

type TypeList struct{}

TypeList is a placeholder for an empty type list.

func (*TypeList) At added in v0.1.6

func (*TypeList) At(int) types.Type

func (*TypeList) Len added in v0.1.6

func (*TypeList) Len() int

type TypeParam added in v0.1.6

type TypeParam struct{ types.Type }

TypeParam is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.

func NewTypeParam added in v0.1.6

func NewTypeParam(name *types.TypeName, constraint types.Type) *TypeParam

NewTypeParam is unsupported at this Go version, and panics.

type TypeParamList added in v0.1.6

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 added in v0.1.6

func RecvTypeParams(sig *types.Signature) *TypeParamList

RecvTypeParams returns a nil slice.

func (*TypeParamList) At added in v0.1.6

func (*TypeParamList) At(int) *TypeParam

func (*TypeParamList) Len added in v0.1.6

func (*TypeParamList) Len() int

type Union added in v0.1.6

type Union struct{ types.Type }

Union is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.

func NewUnion added in v0.1.6

func NewUnion(terms []*Term) *Union

NewUnion is unsupported at this Go version, and panics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL