types

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package types contains target-independent semantic types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assignable

func Assignable(target, value Type) bool

func Equivalent

func Equivalent(left, right Type) bool

Equivalent compares semantic types while ignoring binding-level readonly state. Mutable generic containers use it to avoid unsound argument widening.

func FunctionSignature added in v0.2.3

func FunctionSignature(function Type) ([]Type, Type, bool)

func IsLiteral added in v0.2.3

func IsLiteral(typ Type) bool

Types

type Kind

type Kind string
const (
	Invalid Kind = "invalid"
	// Never is the compiler-internal bottom type for expressions that cannot
	// produce a value because control leaves the current flow.
	Never         Kind = "never"
	Any           Kind = "any"
	Void          Kind = "void"
	Bool          Kind = "bool"
	Int           Kind = "int"
	IntLiteral    Kind = "int_literal"
	Float         Kind = "float"
	String        Kind = "string"
	StringLiteral Kind = "string_literal"
	Bytes         Kind = "bytes"
	StringBuilder Kind = "string_builder"
	Array         Kind = "array"
	Range         Kind = "range"
	Iterable      Kind = "iterable"
	Hash          Kind = "hash"
	Function      Kind = "function"
	Union         Kind = "union"
	Named         Kind = "named"
	Nil           Kind = "nil"
)

type Type

type Type struct {
	Kind Kind
	Name string
	Args []Type
	// Fails is populated only for function values. A nil effect is the pure
	// Never effect, keeping ordinary function types compact.
	Fails    *Type
	Nullable bool
	Readonly bool
}

func CommonType added in v0.1.8

func CommonType(left, right Type) (Type, bool)

CommonType returns the most-specific type that can represent both inputs through portable implicit conversions. It deliberately does not fall back to Any: callers choose whether a missing common type is an error, a union, or a dynamic boundary.

func FromName

func FromName(name string) Type

func FunctionFailure added in v0.2.3

func FunctionFailure(function Type) Type

func FunctionOf added in v0.2.3

func FunctionOf(parameters []Type, result Type) Type

func FunctionWithEffect added in v0.2.3

func FunctionWithEffect(parameters []Type, result, failure Type) Type

func LiteralBase added in v0.2.3

func LiteralBase(typ Type) (Type, bool)

func LiteralFromSource added in v0.2.3

func LiteralFromSource(source string) (Type, bool)

LiteralFromSource returns the compile-time type denoted by an explicit Integer or String literal in a type position. Literal types are erased to their ordinary scalar representation by non-TypeScript backends.

func LiteralUnionBase added in v0.2.3

func LiteralUnionBase(typ Type) (Type, bool)

func UnionOf added in v0.1.8

func UnionOf(input ...Type) Type

UnionOf constructs a canonical union. Nested unions are flattened, equivalent alternatives are removed, and Integer is subsumed by Float because portable Integer-to-Float widening is safe.

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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