Help us shape the future of Go! Take the 2026 Go Developer Survey

typecheck

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package typecheck is the shared, side-effect-free type checker for numscript. It synthesizes the (base) type of every expression, resolves variable types from their declarations, and reports type/name/arity errors — fault-tolerantly (it collects all errors instead of bailing, using TypeAny to avoid cascades).

It is the compiler's checker. The analysis module (LSP/CI) keeps its own unification-based checker: asset-identity inference, feature-version gating and lint-style warnings all stay there, and it does not consume this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadArity

type BadArity struct{ Expected, Actual int }

func (BadArity) Message

func (e BadArity) Message() string

func (BadArity) Severity

func (BadArity) Severity() Severity

type DuplicateVariable

type DuplicateVariable struct{ Name string }

func (DuplicateVariable) Message

func (e DuplicateVariable) Message() string

func (DuplicateVariable) Severity

func (DuplicateVariable) Severity() Severity

type Error

type Error struct {
	Range parser.Range
	Kind  ErrorKind
}

type ErrorKind

type ErrorKind interface {
	Message() string
	Severity() Severity
	// contains filtered or unexported methods
}

ErrorKind is both a typecheck error and a renderable diagnostic (Message + Severity), so callers can push it as a diagnostic without a translation layer.

type InvalidType

type InvalidType struct{ Name string }

func (InvalidType) Message

func (e InvalidType) Message() string

func (InvalidType) Severity

func (InvalidType) Severity() Severity

type Result

type Result struct {
	ExprTypes map[parser.ValueExpr]Type
	VarTypes  map[string]Type
	Errors    []Error
}

func Check

func Check(program parser.Program) Result

type Severity

type Severity = byte

Severity mirrors the LSP DiagnosticSeverity spec (and analysis.Severity, an alias of byte too) so an ErrorKind directly satisfies analysis.DiagnosticKind.

type Type

type Type = string
const (
	TypeNumber   Type = "number"
	TypeString   Type = "string"
	TypeAsset    Type = "asset"
	TypeMonetary Type = "monetary"
	TypeAccount  Type = "account"
	TypePortion  Type = "portion"

	// TypeAny is the type of an expression whose type couldn't be determined
	// (e.g. an unbound variable or an unknown function). It's compatible with
	// everything, so it suppresses cascading errors.
	TypeAny Type = "any"
)

type TypeMismatch

type TypeMismatch struct{ Expected, Got string }

func (TypeMismatch) Message

func (e TypeMismatch) Message() string

func (TypeMismatch) Severity

func (TypeMismatch) Severity() Severity

type UnboundVariable

type UnboundVariable struct{ Name, Type string }

func (UnboundVariable) Message

func (e UnboundVariable) Message() string

func (UnboundVariable) Severity

func (UnboundVariable) Severity() Severity

type UnknownFunction

type UnknownFunction struct{ Name, WrongContext string }

UnknownFunction is either a truly-unknown name (WrongContext == "") or a known builtin used in the wrong context (WrongContext is the context it belongs to, e.g. "statement"). typecheck only ever emits the former.

func (UnknownFunction) Message

func (e UnknownFunction) Message() string

func (UnknownFunction) Severity

func (UnknownFunction) Severity() Severity

Jump to

Keyboard shortcuts

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