0315.
Deep Path with Lenses and var Nested
Field Assignment
- Status: Accepted
- Date: 2026-11-28
- Plan: M26.4
- Relates to: 0278
Context
Tenon records are immutable values: with updates
only top-level fields, and assigning to a record field
(s.x = v) is rejected with E0406.
Updating nested record state in TUI App models, agent
transitions, and composite state therefore requires nested
with boilerplate such as
s = s with { a: s.a with { m: s.a.m.set(k, v) } }.
ADR-0278
already proves last-use uniqueness across arbitrary-depth nested
with chains
(s with { a: s.a with { m: s.a.m.set(…) } }) and
rewrites container updates to in-place *SetUnique
operations without copying.
Decision
- Deep Path
withLenses: Allow dotted field paths and compound field updates insidewithupdate expressions (e.g.,s with { pane.scroll: 0 },s with { stats.hits += 1 }, ors with { a.m: s.a.m.set(k, v) }). Deep path updates desugar in the frontend into nested shallowwithexpressions, grouping sibling paths under shared prefixes, evaluating non-trivial bases once (while keeping pure local bases alias-free for ADR-0278), and evaluating replacement expressions left-to-right. Duplicate or overlapping path updates (such as updating bothaanda.b, ora.xtwice) are rejected deterministically withE0415. varNested Field Assignment: Allow direct and compound field assignment statements (s.x = rhs,s.a.m = rhs,s.a.b += 1) when the root targetsis a mutablevarlocal. The frontend desugarss.p1.p2 = rhsdirectly intos = s with { p1.p2: rhs }(and compound updates into the corresponding nestedwithupdate, with no alias local), preserving immutable value semantics, snapshot safety, and left-to-right evaluation. Field assignment on immutableletbindings or parameters emitsE0204; field assignment on non-local targets (such asf().x = 1) emitsE0406.- Zero-Copy Reuse via ADR-0278: Because both
deep
withlenses andvarnested field assignments desugar strictly in the frontend to the exact alias-free nestedwithAST/IR shapes handled by ADR-0278's field-take liveness analysis, patterns such ass.a.m = s.a.m.set(k, v)ands = s with { a.m: s.a.m.set(k, v) }lower to zero-copy*SetUnique(copies: 0under--report=copies) with noregions, IR, or runtime changes.
Consequences
- Removes nested
withboilerplate from stateful TUI and agent loops without introducing mutable aliasing, reference semantics, or new runtime primitives. - Preserves exact C and
tenon interpbackend parity automatically via frontend desugaring. - Retains existing diagnostic codes
E0406(non-local field assignment target),E0204(immutableletfield assignment), andE0415(duplicate/overlappingwithpaths) without renumbering.