Fix variable resolution of object body params (#1788)

Fixes a regression introduced in Pkl 0.32.
This commit is contained in:
Daniel Chao
2026-07-22 13:04:36 -07:00
committed by GitHub
parent 03792be984
commit 2242cc9c82
5 changed files with 36 additions and 0 deletions
@@ -523,6 +523,13 @@ public final class SymbolTable {
if (scope instanceof LexicalScope lex) {
if (shouldSkip && !(scope instanceof ForGeneratorScope)) {
if (scope instanceof ObjectScope objectScope && objectScope.hasParams()) {
// skipping the object scope should now see the object body params, because the params
// are one level higher than the body itself.
var result = fun.apply(objectScope, levelsUp);
if (result instanceof Parameter parameter) {
//noinspection unchecked
return (R) new Parameter(parameter.slot(), parameter.levelsUp() - 1);
}
levelsUp++;
}
// An EagerGeneratorScope (for `when` predicates) skipped an ObjectScope.
@@ -0,0 +1,9 @@
foo = new Mapping {
default { key ->
for (idx, char in key.split("")) {
["\(char)_\(idx)"] = "hi"
}
}
["zzz"] {}
}
@@ -0,0 +1,8 @@
foo = new Mapping {
default { key ->
when (key is String) {
bar = key
}
}
["x"] {}
}
@@ -0,0 +1,7 @@
foo {
["zzz"] {
["z_0"] = "hi"
["z_1"] = "hi"
["z_2"] = "hi"
}
}
@@ -0,0 +1,5 @@
foo {
["x"] {
bar = "x"
}
}