You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Optional chain resets its receiver: a second o?.field on the same Option reads Some(<empty>) (struct and tuple payloads) #1710
Found while fixing #1503 (tuple element optional chains). Pre-existing: reproduced on the installed compiler (~/.local/bin/with, 2026-09-26) and on the sema-cluster-a stage1.
type P { a: str, b: i32 }
fn main:
let o: Option[P] = Some(P { a: "xyz".clone(), b: 4 })
print(f"{o?.b}")
print(f"{o?.a}")
Prints Some(4) then Some(). Expected Some(4) then Some(xyz): o?.b reads a Copy field through the Option (§10.3, o.map(v => v.b)), which must not consume or reset o. The same with a tuple payload (t?.1 then t?.0). Binding one chain to a local (let s = t?.0) and printing it works, so the read of the FIRST chain is what blanks the receiver, and no "use of moved value" diagnostic reports it: silent wrong value.
Suspect: MirLower.lower_optional_chain moves the whole payload (or schedules the receiver's drop/reset) instead of projecting the field out of a borrowed downcast; --dump-mir of main shows the field reads as copy _43.0/copy _43.1 after a move of the Option into _43.
Expected: the chain observes the receiver; a Copy field materializes, a non-Copy field is a partial move that the move checker reports on the next use.
Fixed on main by the batch-2 stack (#1790/#1791, squash 0e36508): MIR: an optional chain that takes nothing out reads its receiver in place + Sema: an optional chain's read-or-move verdict is Sema's. Evidence with the reseeded compiler (~/.local/bin/with, release digest f1e2e471…, built from 5b6830b by the pinned seed):
Activity
Spec v7.6 (D74): entry sources vs module files; optional-chain field …
MIR: an optional chain that takes nothing out reads its receiver in p…
Sema: an optional chain's read-or-move verdict is Sema's; a chain tha…
Type checker: D74 entry sources and chain moves, field-view bindings (#…
ehartford commentedon Sep 27, 2026
Fixed on main by the batch-2 stack (#1790/#1791, squash 0e36508):
MIR: an optional chain that takes nothing out reads its receiver in place+Sema: an optional chain's read-or-move verdict is Sema's. Evidence with the reseeded compiler (~/.local/bin/with, release digest f1e2e471…, built from 5b6830b by the pinned seed):(Before:
Some(4)thenSome().)