mirror of
https://github.com/apple/pkl.git
synced 2026-07-05 20:51:51 +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) {
|
private boolean isHiddenOrLocalProperty(Object key) {
|
||||||
return key instanceof Identifier
|
return key instanceof ObjectMember member && member.isLocal()
|
||||||
&& (key == Identifier.DEFAULT || ((Identifier) key).isLocalProp());
|
|| key instanceof Identifier identifier
|
||||||
|
&& (key == Identifier.DEFAULT || identifier.isLocalProp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -635,7 +635,7 @@ class EvaluatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `nested pkl-binary rendiring produces correct results`() {
|
fun `nested pkl-binary rendering produces correct results`() {
|
||||||
val evaluator =
|
val evaluator =
|
||||||
with(EvaluatorBuilder.preconfigured()) {
|
with(EvaluatorBuilder.preconfigured()) {
|
||||||
allowedResources.add(Pattern.compile("b64:"))
|
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
|
@Test
|
||||||
fun `power assertions work with test facts with unavailable source section`() {
|
fun `power assertions work with test facts with unavailable source section`() {
|
||||||
val evaluator =
|
val evaluator =
|
||||||
|
|||||||
Reference in New Issue
Block a user