On this page

0021. with updates are postfix and shallow

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

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.