Support local properties in generators
- Dominant language
- Java
- Stars
- 11.5k
- Forks
- 402
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 20
Description
One pain point in Pkl is the inability to create for-generator-local properties.
For example:
```pkl
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.
```pkl
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`).
Contributor guide
Research direction
Start by reviewing the frame changes in #1429 and the roles of ReadFrameSlotNode and WriteFrameSlotNode mentioned in the issue. Confirm that a local property inside a for-generator can be resolved and written to the generator member frame, then verify the Pkl example works without the nested-generator workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100