typeparams

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: BSD-3-Clause Imports: 2 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 extracts the (possibly nil) type parameter node list from n.

func ForNamed

func ForNamed(*types.Named) []*types.TypeName

ForNamed extracts the (possibly empty) type parameter object list from named.

func ForSignature

func ForSignature(*types.Signature) []*types.TypeName

ForSignature extracts the (possibly empty) type parameter object list from sig.

func ForTypeDecl

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

ForTypeDecl extracts the (possibly nil) type parameter node list from n.

func GetInferred

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

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

func HasTypeSet(*types.Interface) bool

HasTypeSet reports if iface has a type set.

func InitInferred

func InitInferred(*types.Info)

InitInferred initializes info to record inferred type information.

func IsComparable

func IsComparable(*types.Interface) bool

IsComparable reports if iface is the comparable interface.

func IsConstraint

func IsConstraint(*types.Interface) bool

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

func IsListExpr(n ast.Node) bool

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

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

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

func UnpackIndex

func UnpackIndex(e *ast.IndexExpr) []ast.Expr

UnpackIndex extracts all index expressions from e. For non-generic code this is always one expression: e.Index, but may be more than one expression for generic type instantiation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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