Skip to content

Move checker double-visits chained method-call receivers: spurious "use of moved value" and doubled diagnostics #573

Closed

Description

@ehartford

Spec reference: §3.8 (by-value consume). Found while conforming the test corpus for #564 on the flipped-gate staged compiler.

A non-Copy local consumed exactly once is rejected when the consuming call is the receiver of a chained method call:

type S { a: str, b: str }

fn mk(a: str) -> S:
    S { a, b: "" }

fn use1(s: S) -> Result[i64, str]:
    let _ = s.a
    if s.b.contains("x"):
        return Ok(7)
    Err("no")

fn main:
    let src = mk("xyz")
    let v = use1(src).unwrap()    // error: use of moved value (src)
    print(int_to_string(v))

Splitting the chain makes it pass, with identical semantics:

    let r = use1(src)
    let v = r.unwrap()            // ok

WITH_DEBUG_MOVE=1 shows the receiver subtree is move-checked twice — src is marked moved on the first walk, then flagged as a moved use on the second:

[move] sym=src tid=84 resolved=84 kind=6
[moved-use] sym=src tid=84 node_kind=24
[move] sym=src tid=84 resolved=84 kind=6

The double walk also duplicates genuine diagnostics: every "use of moved value" inside a chained receiver is reported exactly twice (e.g. the errors for test/behavior/behav_cli_test_command_args.w before its fix). The consumed local can be nested arbitrarily deep in the receiver's argument tree (dispatch(stream, prog, bindings_from(entries)).unwrap() falsely flags entries).

Pre-flip installed compiler accepts the repro. Diagnostic site: src/SemaCheck.w:4348 (check_ident MOVED state) / mark_moved_if_consumed.

Workaround in tree (remove when fixed): test/behavior/issue59_demo_{binding_order_independent,pair_asserts,pair_asserts_dump_mir,pair_print}.w hoist let bindings = bindings_from(entries) out of the chained dispatch(...).unwrap() call.

Activity

  1. ehartford commented on Jun 13, 2026

    @ehartford
    ContributorAuthor

    Root-caused. check_call on a chained call (use1(src).unwrap()) runs the receiver subtree through full, effectful check_expr twice:

    1. The callable-field probe (SemaCheck.w:9012): "is .unwrap a callable struct field?" calls field_access_type_no_diagnostic(callee), which at :6498 does an unconditional check_expr(expr) on the base use1(src) — the inner call's §3.8 gate marks src MOVED. The probe is "no_diagnostic" in name only.
    2. The real check: the probe returns non-callable → check_method_call_parts re-checks the same receiver at :11626; the arg re-check sees MOVED → spurious "use of moved value", and the gate marks again.

    Same family: check_pipeline (|> — confirmed false positive, :8323 + :8339-8365) and check_membership_operator (in, :4880). Collateral from the double visit: every diagnostic in a chained receiver emits twice; note_allocation_site records duplicate alloc sites (doubled no_alloc errors, skewed accounting); duplicate SHARED borrows registered (latent §15 landmine). Idempotent: effect bits, typed_expr_types.

    Recommended fix (validated design, low risk): compute the receiver type once — split field_access_type_no_diagnostic so check_call checks the base itself and probes with a pure field_access_type_from_obj(base_ty, field); add a recv_ty hint param to check_method_call_parts (0 = compute) and pass the known type from check_call/check_pipeline/check_membership. Rejected: cache-first typed_expr_types (stale across generic re-instantiation — check_fn_body_concrete re-checks the same nodes per specialization); a suppress flag (under-checks the genuine callable-field path); deduping only the move-mark (leaves the doubled diagnostics/borrows).

  2. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Closing as fixed on current HEAD: the chained method-call receiver repro compiles with no spurious 'use of moved value' and no doubled diagnostics (the only remaining output is a legitimate runtime unwrap panic from the repro's own Err). The move-checker receiver handling was reworked during the #605/#606/#607 campaign (field-read drop suppression fix + Slice E receiver consume).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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