0021.
with updates are postfix and shallow
- Status: Accepted
- Date: 2026-10-30
- Plan: M4.2
- Review: Language semantics
Context
Immutable record values need a concise update expression that preserves ADR-0020's value semantics and deterministic evaluation order.
Decision
p with { x: 1, y: 2 } is a postfix expression
producing a record of the same type. It evaluates its base once,
then replacement expressions left to right in written order.
Untouched fields come from the evaluated base, even if a
replacement reassigns the base's local. At least one field is
required; names must be unique top-level fields of the record and
values must match their field types. Updates can chain; nested
updates use another with.
Lower using the existing record field and construction operations, preserving the base snapshot and replacement order. Formatting preserves written field order and follows ADR-0028's literal layout and comment rules.
Alternatives considered
- Spread syntax (
{...p, x: 1}) — adds another construction form and obscures the distinction between a base value and replacement fields. - Nested field paths — add path-specific parsing and update semantics; composing shallow updates already expresses nested changes.
Consequences
Updates leave the original value unchanged and work with both backends without new IR operations. Nested changes require explicit intermediate updates; diagnostics reject non-record bases, unknown, duplicate, empty or path fields.