mirror of
https://github.com/apple/pkl.git
synced 2026-06-04 13:00:40 +02:00
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:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user