Skip to content

Sema: a generator value used after g |> stage(...) consumed it is accepted (use after move not reported) #1741

Closed

Description

@ehartford

Spec: §13.4 ("A generator value is consumed once"), §2.2 (use of a moved value is an error). Found on branch gen-push-pull (#1725); reproduces on the gen-push-impl base.

Repro:

use std.generators.{take, collect}

gen fn words(all: Vec[str]) -> str:
    for s in all:
        yield s

fn main:
    let g = words(["a".clone(), "b".clone()])
    let v = g |> take(1) |> collect()
    print(v.len())
    for x in g:
        print(x)

Expected: error: use of moved value at for x in g. Actual: compiles; prints 1 and the loop runs over the moved-out (blanked) value — nothing, no double free under --debug-alloc.

The direct call take(g, 1) and (on gen-push-pull) g.pull() report the move. The pipeline path (check_generic_pipeline_call, SemaCheck.w) calls check_generic_call with the left-hand side as argument 0 but never marks it moved; the generic free-call path in check_call marks every by-value argument moved (mark_moved_if_consumed) when the callee has no signature yet.

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