Eagerly check listing/mapping in iterables (#752)

There is currently a bug around resolving variables within the iterable of a for
generator or spread syntax (https://github.com/apple/pkl/issues/741)

Normally, mappings/listings are type-checked lazily. However, this results in the said
bug getting widened, for any object members declared in the iterable.

As a workaround for now, prevent the bug from being any worse by ensuring that these
object members are eagerly typechecked.
This commit is contained in:
Daniel Chao
2024-10-31 14:22:24 -07:00
committed by GitHub
parent 1be1fe4863
commit 66d751f093
10 changed files with 126 additions and 11 deletions
@@ -0,0 +1,33 @@
class Aviary {
birds: Listing<Bird>
}
class Bird {
age: Int
}
function Bird(_age: Int) = new Bird { age = _age }
res1 {
for (i in IntSeq(1, 1)) {
for (j in
new Aviary {
birds {
Bird(i)
}
}.birds
) {
j
}
}
}
res2 {
for (i in IntSeq(1, 1)) {
...new Aviary {
birds {
Bird(i)
}
}.birds
}
}
@@ -0,0 +1,10 @@
res1 {
new {
age = 1
}
}
res2 {
new {
age = 1
}
}