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