apple/pkl · error · VmException
listingAmendmentCannotHaveParameters
listingAmendmentCannotHaveParameters
Error message
Expected a function that returns a `Listing`, but got a `Listing`.
What it means
A Listing amendment must be a plain object literal — it cannot introduce function parameters, because the amended value is a `Listing` produced by an expression, not a parameterized object constructor. `checkIsValidListingAmendment` throws this when `parametersDescriptor` is non-null, i.e. the amendment literal declares a parameter list.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java:158
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")
@TruffleBoundary
@Idempotent
protected final boolean checkIsValidMappingAmendment() {
if (checkedIsValidMappingAmendment) return true;
for (var member : EconomicMaps.getValues(members)) {
if (member.isLocal()) continue;
View on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove the parameter list from the Listing amendment and inline the values
- If parameterization is required, amend a class whose property returns the Listing, parameterizing at that level instead
- Compute the elements in a separate expression/function and assign the result rather than parameterizing the amendment
Example fix
// before
items { (x) { [0] = x } }
// after
items { [0] = 42 }
Defensive patterns
Strategy: validation
Validate before calling
// Listing amendments take no parameter list: write items { [0] = v } not items { (x) { ... } }
Prevention
- Only class-amending literals support parameter lists
- Parameterize with functions that return Listings instead
When it happens
Trigger: Writing `items { (x) { ... } }`-style or `amends (a) -> ...` parameterized amendment targeting a Listing; applying a function-shaped object literal to a Listing parent.
Common situations: Copy-pasting a parameterized `amends` pattern from a class-typed object onto a Listing; misunderstanding that only class-amending literals support parameters.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- listingAmendmentCannotHaveParameters
- wrongFunctionAmendmentParameterCount
- mappingAmendmentCannotHaveParameters
- elementIndexOutOfRange
- defaultMember/cannotFindMember
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/b178bf70fb2523ac.
Report an issue: GitHub.