apple/pkl · error · VmException
objectCannotHaveProperty
objectCannotHaveProperty
Error message
Object of type `{0}` cannot have a property (other than `default`). What it means
A `Listing` can only contain positional elements plus an optional `default` element; it cannot carry named properties. `checkIsValidListingAmendment` throws `objectCannotHaveProperty` (parameterized with the base `Listing` class) when a Listing amendment declares a named member other than `default`.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java:150
if (!(key instanceof Long)) {
CompilerDirectives.transferToInterpreter();
throw exceptionBuilder()
.evalError("wrongListingKeyType", new ProgramValue("", VmUtils.getClass(key)))
.withSourceSection(member.getHeaderSection())
.build();
}
long index = (long) key;
if (index < 0) {
// defer handling of negative index to checkMaxListingMemberIndex() (gives more uniform
// error messages)
maxIndex = Long.MAX_VALUE;
break;
} else if (index > maxIndex) {
maxIndex = index;
}
} else if (memberName != Identifier.DEFAULT) {
throw exceptionBuilder()
.evalError("objectCannotHaveProperty", BaseModule.getListingClass())
.withSourceSection(member.getHeaderSection())
.build();
}
}
if (parametersDescriptor != null) {
throw exceptionBuilder()
.evalError("listingAmendmentCannotHaveParameters")
.withSourceSection(getParentNode().getSourceSection())
.build();
}
maxListingMemberIndex = maxIndex;
return true;
}
@SuppressWarnings("SameReturnValue")View on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove the named property from the Listing amendment
- Move the property to an element: `["name"]` won't work either — instead put the data into elements via `[0] = ...` or restructure the container as a `Mapping`
- Use `default { ... }` if you intended to set the default element
Example fix
// before (items: Listing)
items { label = "x"; [0] = 1 }
// after
items { [0] = 1 }
Defensive patterns
Strategy: validation
Validate before calling
// In a Listing amendment, allowed members are only [i] = v and default { ... } — review body before eval.
Prevention
- Never mix named properties into Listing bodies
- Restructure to a class-based object if named fields are needed alongside elements
When it happens
Trigger: Adding a named property inside a Listing amendment, e.g. `items { name = "x" }` where `items` is a `Listing`; forgetting that within a Listing body only `[index] = ...` and `default { ... }` are legal.
Common situations: Mixing Mapping-style and Listing-style member syntax in one amendment; pasting property overrides into a Listing block; schema drift where a field was moved from a property to an element.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/e6b8e05d91d6d87e.
Report an issue: GitHub.