Skip to content

An if whose arms are fields (if c: x.s else: y.s) joins as a view but still blanks the field — later reads see "" #1409

Closed

Description

@ehartford

Spec: §2.2 (a field never moves out implicitly, D32) / D27 ("a binding names what is there"). Split from #1380, which covers arms that are whole bindings.

use std.process
type S { s: str }
fn main:
    let x = S { s: "x" ++ "y" }
    let y = S { s: "u" ++ "v" }
    let c = args().len() > 0
    let p = if c: x.s else: y.s
    let q = if c: x.s else: y.s
    print(f"[{p}] [{q}] [{x.s}]")

Actual (installed v0.15.2.1; also the #1380 branch): compiles, prints [xy] [] [], debug-alloc: leak count=0.

Expected, one of:

Mechanism: lower_if lowers the arm with lower_expr, which moves the field (OK_MOVE of _x.f0) and queues a reset-on-move. flush_pending_resets_since then blanks the field inside the branch. Only after that does last_if_result_view classify the join as a view. So the result is a view of a field that was just blanked. Sema records no move (mark_moved_if_consumed never sees the arm), so nothing is diagnosed.

Found while fixing #1380.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions