diff --git a/pkl-core/src/main/java/org/pkl/core/runtime/VmDynamic.java b/pkl-core/src/main/java/org/pkl/core/runtime/VmDynamic.java index c8915f18..a3dbb6be 100644 --- a/pkl-core/src/main/java/org/pkl/core/runtime/VmDynamic.java +++ b/pkl-core/src/main/java/org/pkl/core/runtime/VmDynamic.java @@ -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()); } } diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/pklbinary/localMembers.msgpack.yaml.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/pklbinary/localMembers.msgpack.yaml.pkl new file mode 100644 index 00000000..947d3af7 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/pklbinary/localMembers.msgpack.yaml.pkl @@ -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 diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/pklbinary/localMembers.msgpack.yaml b/pkl-core/src/test/files/LanguageSnippetTests/output/pklbinary/localMembers.msgpack.yaml new file mode 100644 index 00000000..7a57e1f8 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/pklbinary/localMembers.msgpack.yaml @@ -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' + - [] \ No newline at end of file diff --git a/pkl-core/src/test/kotlin/org/pkl/core/EvaluatorTest.kt b/pkl-core/src/test/kotlin/org/pkl/core/EvaluatorTest.kt index 733eed6c..cf0bee38 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/EvaluatorTest.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/EvaluatorTest.kt @@ -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 =