typecheck

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NativeFieldIsFunction

func NativeFieldIsFunction(name, field string) (bool, bool)

func NativeModuleFields

func NativeModuleFields(name string) (map[string]bool, bool)

func NativeModuleNames

func NativeModuleNames() []string

func Same

func Same(a, b *Type) bool

Types

type FunctionShape

type FunctionShape struct {
	Params     []*Type
	Returns    []*Type
	IsVararg   bool
	VarargType *Type

	TypeParams []string
	TypeBounds map[string]*Type

	Struct *StructCtor
}

type Indexer

type Indexer struct {
	Key   *Type
	Value *Type
}

type Kind

type Kind int
const (
	KindNumber Kind = iota
	KindString
	KindBoolean
	KindNil
	KindAny
	KindUnknown
	KindNever
	KindFunction
	KindTable
	KindUnion
	KindLiteral
	KindTypeParam
)

type LiteralValue

type LiteralValue struct {
	Base Kind
	Str  string
	Num  float64
	Bool bool
	Raw  string
}

type Options

type Options struct {
	Strict bool
	REPL   bool
}

type StructCtor

type StructCtor struct {
	Name  string
	Shape *TableShape
}

type TableField

type TableField struct {
	Key  string
	Type *Type
}

type TableShape

type TableShape struct {
	Fields  []TableField
	Indexer *Indexer
}

type Type

type Type struct {
	Kind Kind

	Fn    *FunctionShape
	Table *TableShape
	Union []*Type
	Lit   *LiteralValue

	Bound *Type

	AliasName string
}

func Intersect

func Intersect(members ...*Type) *Type

func NewBooleanLiteral

func NewBooleanLiteral(v bool, raw string) *Type

func NewFunction

func NewFunction(params []*Type, returns []*Type, isVararg bool, varargType *Type) *Type

func NewNumberLiteral

func NewNumberLiteral(v float64, raw string) *Type

func NewStringLiteral

func NewStringLiteral(v, raw string) *Type

func NewTable

func NewTable(fields []TableField, indexer *Indexer) *Type

func NewUnion

func NewUnion(members ...*Type) *Type

func Optional

func Optional(t *Type) *Type

func (*Type) String

func (t *Type) String() string

type TypeError

type TypeError struct {
	Line    int
	Code    string
	Message string
	Got     *Type
	Want    *Type

	// Field is the path inside a table literal where a contextual check
	// failed ("age", "address.city", "[2]"); empty elsewhere.
	Field string
}

func Check

func Check(prog *ast.Program, opts Options) []TypeError

func (*TypeError) Format

func (e *TypeError) Format() string

type TypeErrors

type TypeErrors struct {
	Errors []TypeError
}

func (*TypeErrors) Error

func (te *TypeErrors) Error() string

Jump to

Keyboard shortcuts

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