Local variables inside for loops yield an error
- Dominant language
- Java
- Stars
- 11.5k
- Forks
- 402
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 20
Description
Code:
```pkl
hidden xs = new Listing { 1 2 3 }
object {
for (x in xs) {
local plusOne = x + 1
plusOne
}
}
```
On evaluation yields the following error:
```
A for-generator cannot generate object properties (only entries and elements).
```
Instead, expected to produce object with entries `2 3 4`.
Version:
```
% pkl --version
Pkl 0.26.0 (macOS 14.3.1, native)
```
Contributor guide
Research direction
Start by reproducing the issue with the provided Pkl snippet on the reported version, then trace the compiler handling of for-generators and local variables inside their bodies. The fix is done when the example evaluates successfully and produces entries 2, 3, and 4 without the object-property error.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100