Correctly count regular members of Dynamic (#1632)

Previously, `VmDynamic.isHiddenOrLocalProperty` didn't correctly
identify locals whose cache key is an `ObjectMember` instead of an
`Identifier`, causing `VmDynamic. getRegularMemberCount` to return an
incorrect value. This caused some renderers to produce incorrect output.

Resolves #1631
This commit is contained in:
Jen Basch
2026-06-01 20:27:19 -07:00
committed by GitHub
parent 7dd2bc67de
commit 18af04c2ec
2 changed files with 46 additions and 3 deletions
@@ -158,7 +158,8 @@ public final class VmDynamic extends VmObject {
}
private boolean isHiddenOrLocalProperty(Object key) {
return key instanceof Identifier
&& (key == Identifier.DEFAULT || ((Identifier) key).isLocalProp());
return key instanceof ObjectMember member && member.isLocal()
|| key instanceof Identifier identifier
&& (key == Identifier.DEFAULT || identifier.isLocalProp());
}
}
@@ -635,7 +635,7 @@ class EvaluatorTest {
}
@Test
fun `nested pkl-binary rendiring produces correct results`() {
fun `nested pkl-binary rendering produces correct results`() {
val evaluator =
with(EvaluatorBuilder.preconfigured()) {
allowedResources.add(Pattern.compile("b64:"))
@@ -696,6 +696,48 @@ class EvaluatorTest {
}
}
@Test
fun `objects with object locals are encoded correctly`() {
val data =
evaluator.evaluateOutputBytes(
text(
"""
import "pkl:pklbinary"
dynamic: Dynamic = new {
local foo = new Test {}
bar = foo
}
listing: Listing = new {
local foo = new Test {}
foo
}
mapping: Mapping = new {
local foo = new Test {}
["bar"] = foo
}
`class`: MyClass = new {
local foo = new Test {}
bar = foo
}
class MyClass {
bar: Test
}
class Test
output {
renderer = new pklbinary.Renderer {}
}
"""
.trimIndent()
)
)
assertThatCode { PklBinaryDecoder.decode(data) }.doesNotThrowAnyException()
}
@Test
fun `power assertions work with test facts with unavailable source section`() {
val evaluator =