Skip to content

Commit c9f3823

Browse files
authored
Touch ups around local members (#1633)
* Add assertion if ObjectMember key in cachedValues is not local (should never happen) * Move test to snippet tests
1 parent 18af04c commit c9f3823

4 files changed

Lines changed: 92 additions & 45 deletions

File tree

pkl-core/src/main/java/org/pkl/core/runtime/VmDynamic.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,12 @@ public int getRegularMemberCount() {
158158
}
159159

160160
private boolean isHiddenOrLocalProperty(Object key) {
161-
return key instanceof ObjectMember member && member.isLocal()
162-
|| key instanceof Identifier identifier
163-
&& (key == Identifier.DEFAULT || identifier.isLocalProp());
161+
// only local members have the entire `ObjectMember` stored as a key in cachedValues
162+
if (key instanceof ObjectMember member) {
163+
assert member.isLocal();
164+
return true;
165+
}
166+
return key instanceof Identifier identifier
167+
&& (key == Identifier.DEFAULT || identifier.isLocalProp());
164168
}
165169
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extends ".../pklbinaryTest.pkl"
2+
3+
dynamic: Dynamic = new {
4+
local foo = new Test {}
5+
bar = foo
6+
}
7+
8+
listing: Listing = new {
9+
local foo = new Test {}
10+
foo
11+
}
12+
13+
mapping: Mapping = new {
14+
local foo = new Test {}
15+
["bar"] = foo
16+
}
17+
18+
`class`: MyClass = new {
19+
local foo = new Test {}
20+
bar = foo
21+
}
22+
23+
class MyClass {
24+
bar: Test
25+
}
26+
27+
class Test
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
- 1
2+
- 'localMembers.msgpack.yaml'
3+
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
4+
-
5+
-
6+
- 16
7+
- 'dynamic'
8+
-
9+
- 1
10+
- 'Dynamic'
11+
- 'pkl:base'
12+
-
13+
-
14+
- 16
15+
- 'bar'
16+
-
17+
- 1
18+
- 'localMembers.msgpack.yaml#Test'
19+
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
20+
- []
21+
-
22+
- 16
23+
- 'listing'
24+
-
25+
- 5
26+
-
27+
-
28+
- 1
29+
- 'localMembers.msgpack.yaml#Test'
30+
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
31+
- []
32+
-
33+
- 16
34+
- 'mapping'
35+
-
36+
- 3
37+
-
38+
'bar':
39+
- 1
40+
- 'localMembers.msgpack.yaml#Test'
41+
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
42+
- []
43+
-
44+
- 16
45+
- 'class'
46+
-
47+
- 1
48+
- 'localMembers.msgpack.yaml#MyClass'
49+
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
50+
-
51+
-
52+
- 16
53+
- 'bar'
54+
-
55+
- 1
56+
- 'localMembers.msgpack.yaml#Test'
57+
- 'file:///$snippetsDir/input/pklbinary/localMembers.msgpack.yaml.pkl'
58+
- []

pkl-core/src/test/kotlin/org/pkl/core/EvaluatorTest.kt

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -696,48 +696,6 @@ class EvaluatorTest {
696696
}
697697
}
698698

699-
@Test
700-
fun `objects with object locals are encoded correctly`() {
701-
val data =
702-
evaluator.evaluateOutputBytes(
703-
text(
704-
"""
705-
import "pkl:pklbinary"
706-
707-
dynamic: Dynamic = new {
708-
local foo = new Test {}
709-
bar = foo
710-
}
711-
listing: Listing = new {
712-
local foo = new Test {}
713-
foo
714-
}
715-
mapping: Mapping = new {
716-
local foo = new Test {}
717-
["bar"] = foo
718-
}
719-
`class`: MyClass = new {
720-
local foo = new Test {}
721-
bar = foo
722-
}
723-
724-
class MyClass {
725-
bar: Test
726-
}
727-
728-
class Test
729-
730-
output {
731-
renderer = new pklbinary.Renderer {}
732-
}
733-
"""
734-
.trimIndent()
735-
)
736-
)
737-
738-
assertThatCode { PklBinaryDecoder.decode(data) }.doesNotThrowAnyException()
739-
}
740-
741699
@Test
742700
fun `power assertions work with test facts with unavailable source section`() {
743701
val evaluator =

0 commit comments

Comments
 (0)