Touch ups around local members (#1633)

* Add assertion if ObjectMember key in cachedValues is not local (should never happen)
* Move test to snippet tests
This commit is contained in:
Daniel Chao
2026-06-01 20:47:46 -07:00
committed by GitHub
parent 18af04c2ec
commit c9f3823952
4 changed files with 92 additions and 45 deletions
@@ -158,8 +158,12 @@ public final class VmDynamic extends VmObject {
}
private boolean isHiddenOrLocalProperty(Object key) {
return key instanceof ObjectMember member && member.isLocal()
|| key instanceof Identifier identifier
&& (key == Identifier.DEFAULT || identifier.isLocalProp());
// only local members have the entire `ObjectMember` stored as a key in cachedValues
if (key instanceof ObjectMember member) {
assert member.isLocal();
return true;
}
return key instanceof Identifier identifier
&& (key == Identifier.DEFAULT || identifier.isLocalProp());
}
}
@@ -0,0 +1,27 @@
extends ".../pklbinaryTest.pkl"
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
@@ -0,0 +1,58 @@
- 1
- 'localMembers.msgpack.yaml'
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
-
-
- 16
- 'dynamic'
-
- 1
- 'Dynamic'
- 'pkl:base'
-
-
- 16
- 'bar'
-
- 1
- 'localMembers.msgpack.yaml#Test'
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
- []
-
- 16
- 'listing'
-
- 5
-
-
- 1
- 'localMembers.msgpack.yaml#Test'
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
- []
-
- 16
- 'mapping'
-
- 3
-
'bar':
- 1
- 'localMembers.msgpack.yaml#Test'
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
- []
-
- 16
- 'class'
-
- 1
- 'localMembers.msgpack.yaml#MyClass'
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
-
-
- 16
- 'bar'
-
- 1
- 'localMembers.msgpack.yaml#Test'
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
- []
@@ -696,48 +696,6 @@ 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 =