transform

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package transform provides type transformation operations.

This package implements type transformations applied during synthesis, including spec-based return type computation and type matching.

Spec Return Transformation

For functions with type specs (generics, overloads):

---@generic T
---@param arr T[]
---@return T
function first(arr) ... end

The package computes the concrete return type by:

  1. Matching argument types to parameter specs
  2. Binding type variables
  3. Substituting in the return type spec

Spec Matching

The specmatch subpackage handles pattern matching against type specs, extracting type variable bindings from argument types.

Integration

Transformations are applied during call synthesis to compute concrete return types from generic function specs.

Package transform provides return type transforms owned by the compiler layer. This package applies spec and effect transforms to synthesized return types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyEffectTransform

func ApplyEffectTransform(fn *typ.Function, args []typ.Type, returnIdx int, baseReturn typ.Type) typ.Type

ApplyEffectTransform applies return type effects to compute the actual return type. If the function has a contract.Spec with a Return effect, the transform is applied to derive the concrete return type from the argument types.

func ApplySpecReturnCases

func ApplySpecReturnCases(fn *typ.Function, args []typ.Type) typ.Type

ApplySpecReturnCases evaluates contract.ReturnSpec cases against argument types. This is pure type-based matching that works when argument types are resolved to literal types. The compiler uses this as a fallback when AST-pattern matching (for inline table constructors) doesn't produce a result.

Ownership: This function provides the pure type-based logic. The compiler owns the decision of when to apply spec returns and coordinates between AST-pattern matching and type-based matching.

func ReturnTypeFromSpec

func ReturnTypeFromSpec(spec *contract.Spec, args []ast.Expr) typ.Type

ReturnTypeFromSpec returns the first matching spec return case type for the given call arguments. Returns nil if no case matches.

Types

This section is empty.

Jump to

Keyboard shortcuts

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