Skip to content

D69: a comprehension clause over a generator (§13.6: [f(x) for x in g]) #1727

Closed

Description

@ehartford

Spec: §13.6 (a comprehension clause's for PATTERN in EXPR is §13.5's iteration) with §13.4 (D69).

[x * 2 for x in upto(3)] where upto is a gen fn. Before D69 the program compiled and hung at run time (the pull-model next() path never finished); with the D69 push lowering (gen-push-impl) a comprehension clause over a Gen[T] is not lowered, so it is a compile error citing this issue.

Expected: the clause runs the remaining clauses and the leaf as the body each calls (the same closure lowering as for x in g, lower_for_gen), stopping never (a comprehension consumes the whole generator).

Repro:

gen fn upto(n: i32) -> i32:
    for i in 0..n:
        yield i
fn main:
    let v = [x * 2 for x in upto(3)]
    print(v.len())

Workaround: var v: Vec[i32] = Vec.new() + for x in upto(3): v.push(x * 2), or upto(3) |> map(it * 2) |> collect[Vec]().

Activity

  1. 4 remaining items

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