Skip to content

Support local properties in generators #1580

Description

@bioball

One pain point in Pkl is the inability to create for-generator-local properties.

For example:

foo {
  for (elem in bar) {
    local qux = doSomething(elem) // <-- error; for generators cannot have properties
    ["prop1"] = qux
    ["prop2"] = qux
  }
}

Currently one workaround is to wrap the for-generator in a another for-generator, e.g.

foo {
  for (qux in List(doSomething(elem)) {
    for (elem in bar) {
      ["prop1"] = qux
      ["prop2"] = qux
    }
  }
}

This should be doable after #1429 is merged; local properties can be written to the generator member frame, and we can resolve local properties to that exact slot (using ReadFrameSlotNode and WriteFrameSlotNode).

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