apple/pkl · error · VmException
objectAmendmentCannotHaveParameters
objectAmendmentCannotHaveParameters
Error message
Expected a function that returns an object, but got an object.
What it means
When amending an object produced by a function call (e.g. in `new` or an object amendment position), Pkl expects either a plain object or a function returning an object. An amendment targeting a Dynamic object that declares parameters is rejected: parameterized object literals cannot be amended this way.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorObjectLiteralNode.java:237
@TruffleBoundary
protected void fallback(Object parent) {
var value = parent;
// blame the non-null type (e.g. blame `Duration` instead of `Null` in the case of `Duration?`)
if (value instanceof VmNull vmNull) {
value = getNullDefaultValue(vmNull);
}
VmUtils.checkIsInstantiable(
value instanceof VmClass vmClass ? vmClass : VmUtils.getClass(value), getParentNode());
throw exceptionBuilder().unreachableCode().build();
}
@Idempotent
protected boolean checkObjectCannotHaveParameters() {
if (parametersDescriptor == null) return true;
CompilerDirectives.transferToInterpreter();
throw exceptionBuilder()
.evalError("objectAmendmentCannotHaveParameters")
.withLocation(getParentNode())
.build();
}
@Idempotent
protected boolean checkListingCannotHaveParameters() {
if (parametersDescriptor == null) return true;
CompilerDirectives.transferToInterpreter();
throw exceptionBuilder()
.evalError("listingAmendmentCannotHaveParameters")
.withLocation(getParentNode())
.build();
}
@Idempotent
protected boolean checkMappingCannotHaveParameters() {View on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove the parameter list from the amendment; amend the object directly (`obj { ... }`).
- If parameters are intended, call the function: `obj(params) { ... }` so the target is a function returning an object.
- Verify the target expression's type — a Dynamic object cannot accept amendment parameters.
Example fix
// before
base { (x) ->
y = x
}
// after
base {
y = 42
} Defensive patterns
Strategy: validation
Prevention
- Reserve `(p) -> { ... }` parameter syntax for functions; use plain `{ ... }` for object amendments.
- Check the target's type before amending: a Dynamic object takes no parameters.
- Call functions with parentheses instead of amendment parameter syntax.
When it happens
Trigger: Applying an amendment (`foo { ... }`) to an expression that is a Dynamic object (not a function returning one), where the amendment carries a parameters list (`(x) -> ...`), via `checkObjectCannotHaveParameters` in GeneratorObjectLiteralNode.
Common situations: Confusing `new Foo { ... }` / `Foo { ... }` amendment syntax with function-call syntax; adding `(param) ->` to an amendment of a plain object instead of a function; migrating code where the target changed from a function to an object.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- cannotAnalyzeBecauseSyntaxError
- invalidTripleDotSyntax
- forWhenBodyCannotHaveParameters
- invalidTypeName
- unseparatedObjectMembers
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/a04718523e859f44.
Report an issue: GitHub.