typestest

package
v0.0.0-...-0bbbf19 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExpr

func CheckExpr(t testing.TB, fset *token.FileSet, pkg *types.Package, pos token.Pos, expr ast.Expr, info *types.Info)

CheckExpr type checks the expression expr as if it had appeared at position pos of package pkg. [Type] information about the expression is recorded in info. The expression may be an identifier denoting an uninstantiated generic function or type.

If pkg == nil, the [Universe] scope is used and the provided position pos is ignored. If pkg != nil, and pos is invalid, the package scope is used. Otherwise, pos must belong to the package.

An error is returned if pos is not within the package or if the node cannot be type-checked.

Note: Eval and CheckExpr should not be used instead of running Check to compute types and values, but in addition to Check, as these functions ignore the context in which an expression is used (e.g., an assignment). Thus, top-level untyped constants will return an untyped type rather than the respective context-specific type.

func Eval

func Eval(t testing.TB, fset *token.FileSet, pkg *types.Package, pos token.Pos, expr string) types.TypeAndValue

Eval returns the type and, if constant, the value for the expression expr, evaluated at position pos of package pkg, which must have been derived from type-checking an AST with complete position information relative to the provided file set.

The meaning of the parameters fset, pkg, and pos is the same as in CheckExpr. An error is returned if expr cannot be parsed successfully, or the resulting expr AST cannot be type-checked.

func Instantiate

func Instantiate(t testing.TB, ctxt *types.Context, orig types.Type, targs []types.Type, validate bool) types.Type

Instantiate instantiates the type orig with the given type arguments targs. orig must be an *Alias, *Named, or *Signature type. If there is no error, the resulting Type is an instantiated type of the same kind (*Alias, *Named or *Signature, respectively).

Methods attached to a *Named type are also instantiated, and associated with a new *Func that has the same position as the original method, but nil function scope.

If ctxt is non-nil, it may be used to de-duplicate the instance against previous instances with the same identity. As a special case, generic *Signature origin types are only considered identical if they are pointer equivalent, so that instantiating distinct (but possibly identical) signatures will yield different instances. The use of a shared context does not guarantee that identical instances are deduplicated in all cases.

If validate is set, Instantiate verifies that the number of type arguments and parameters match, and that the type arguments satisfy their respective type constraints. If verification fails, the resulting error may wrap an *ArgumentError indicating which type argument did not satisfy its type parameter constraint, and why.

If validate is not set, Instantiate does not verify the type argument count or whether the type arguments satisfy their constraints. Instantiate is guaranteed to not return an error, but may panic. Specifically, for *Signature types, Instantiate will panic immediately if the type argument count is incorrect; for *Named types, a panic may occur later inside the *Named API.

Types

This section is empty.

Jump to

Keyboard shortcuts

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