Fix length of listings with computed index (#797)

Motivation:
The following expression evaluates to 2 instead of 1:
new Listing { "value" } { [0 + 0] = "override" }.length

Changes:
- fix length computation in EntriesLiteralNode
- improve `api/listing` tests
- make snippet test failures diffable in IntelliJ

Result:
- fixes https://github.com/apple/pkl/issues/780
- improved dev experience in IntelliJ
This commit is contained in:
translatenix
2024-11-13 10:29:37 -08:00
committed by GitHub
parent 3f91824dc2
commit 9faff5e551
4 changed files with 241 additions and 5 deletions

View File

@@ -43,15 +43,15 @@ public abstract class EntriesLiteralNode extends SpecializedObjectLiteralNode {
@Children private final ExpressionNode[] keyNodes;
private final ObjectMember[] values;
public EntriesLiteralNode(
protected EntriesLiteralNode(
SourceSection sourceSection,
VmLanguage language,
// contains local properties and default property (if present)
// does *not* contain entries with constant keys to maintain definition order of entries
String qualifiedScopeName,
boolean isCustomThisScope,
@Nullable FrameDescriptor parametersDescriptor,
UnresolvedTypeNode[] parameterTypes,
// contains local properties and default property (if present)
// does *not* contain entries with constant keys to maintain definition order of entries
UnmodifiableEconomicMap<Object, ObjectMember> members,
ExpressionNode[] keyNodes,
ObjectMember[] values) {
@@ -103,7 +103,8 @@ public abstract class EntriesLiteralNode extends SpecializedObjectLiteralNode {
frame.materialize(),
parent,
createListMembers(frame, parent.getLength()),
parent.getLength() + keyNodes.length);
// `[x] = y` overrides existing element and doesn't increase length
parent.getLength());
}
@Specialization