Type inference
Platform spec node
Type inference
Spec standingStandard
No architecture decision records under adr/ for this feature yet. Standard features must
publish at least one ADR or keep a ## Decisions summary on the hub.
- Enums and match Algebraic enums and exhaustive `match` tie data representation to control flow. Lowering must preserve discriminant layout described in Execution where relevant.
- Method dispatch Virtual dispatch, overload resolution, and receiver rules decide which code runs. Interop and codegen consume the same dispatch table model.
- Type inference Local type inference reduces annotation burden while keeping programs predictable. The inference algorithm is specified here; diagnostics reference these rules.
- Types The type grammar (nominal types, generics, ref T, Option T) is the backbone of static checking. All analysis phases share these definitions.
0 revisions (git unavailable at build; counts may be empty)
No commits recorded for this path.
| Section id | Required | Found |
|---|---|---|
scope | yes | yes |
features | yes | yes |
Full tree: run pnpm verify:platform-spec-layout (writes src/generated/platform-spec-layout-report.json).
Normative specification
Section titled “Normative specification”Defines when types must be written explicitly and when the compiler may infer types from context. Ground rules for type expressions are in Types.
Inference sites
Section titled “Inference sites”let name = expr(inferred let) must infer the variable type fromexprwhen unambiguous.let T name = expr(typed let) must checkexpragainstT; no inference ofTfrom the initializer alone.- Function return types on top-level functions should be explicit; when omitted, inference may use body yield rules; explicit annotation is recommended for public APIs.
- Generic arguments at call sites may be inferred from parameter types when a unique solution exists (E1203 when missing).
- Lambda parameter types may be inferred from expected function type; untyped lambda parameters require contextual type (E1202 when missing).
Static rules
Section titled “Static rules”- Inference must not widen beyond the declared or inferred constraint (no implicit numeric promotion across unrelated primitives in v0.1).
- Ambiguous inference must error with E1202 (missing annotation) rather than pick an arbitrary type.
- Enum constructors and struct literals must have sufficient context to resolve the target type or require explicit qualification.
Dynamic semantics
Section titled “Dynamic semantics”Inference affects compile-time only; no runtime reflection of inferred types beyond debug metadata.
Diagnostics
Section titled “Diagnostics”E1202 missing annotation; E1206 mismatch after inference. Registry: Diagnostic code registry.
Conformance
Section titled “Conformance”Reference compiler tests for let inference and generic call inference must pass for L2 claims.
Decisions
Section titled “Decisions”- D-LM-INF-001 — Fail on ambiguity: Prefer errors over guessing when multiple types satisfy constraints.
- D-LM-INF-002 — Public API annotations: Exported functions should declare return types even when inference succeeds.
- D-LM-INF-003 — No nullable inference: Inference must not introduce nullable or
optionaltypes; useOption<T>explicitly. - D-LM-INF-004 — Contextual lambdas: Untyped lambda parameters require an expected function type from the enclosing expression.
Platform view
Section titled “Platform view”Local type inference reduces annotation burden while keeping programs predictable. The inference algorithm is specified here; diagnostics reference these rules.