Skip to content

D69: generic generator functions and generator methods (gen fn f[T], gen fn in impl) #1724

Closed

Description

@ehartford

Spec: §13.4 (D69, push generators).

A gen fn with type parameters, or a gen fn declared as a method inside an impl/type/extend block, is not implemented. Before D69 both failed obscurely (generic: "MIR lowering failed for function 'main'"; method: "undefined variable self" / "unknown method"). The D69 lowering (gen-push-impl) makes both a loud compile error naming this issue.

Repro:

gen fn twice[T](x: T) -> T:
    yield x
    yield x
fn main:
    for v in twice(3): print(v)
type W { n: i32 }
impl W:
    gen fn upto() -> i32:
        var i = 0
        while i < self.n:
            yield i
            i += 1

Expected: both compile; the generator value of a generic gen fn is a specialization of the per-gen-fn state struct (its arguments), each and the producer are specialized with it; a gen method stores its receiver as the first argument.

Actual: compile error citing this issue.

Activity

  1. 2 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