apple/pkl · error · VmException
cannotAmendFixedProperty
cannotAmendFixedProperty
Error message
Cannot amend fixed property `{0}`. What it means
Pkl properties declared `fixed` (or `const`) cannot be amended or assigned in an object that amends their declaring class. `checkIsValidTypedAmendment` detects a member overriding a fixed/const class property and picks `cannotAmendFixedProperty` when the member is an amends-style declaration (header == body section), or `cannotAssignFixedProperty` otherwise.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java:98
if (!parentClass.hasProperty(memberName)) {
throw exceptionBuilder()
.cannotFindProperty(parentClass.getPrototype(), memberName, false, false)
.withSourceSection(member.getHeaderSection())
.build();
}
var classProperty = parentClass.getProperty(memberName);
if (classProperty != null && classProperty.isConstOrFixed()) {
// tailor error message based on whether an amends declaration is used or not
// (i.e. `friends {}` vs. `friends = new {}`)
// an amends declaration's body section includes the header section, whereas normal property
// assignment's body section is the section after the equal sign.
var isAmendsDeclaration =
member.getHeaderSection().getCharIndex() == member.getBodySection().getCharIndex();
var errMsg = isAmendsDeclaration ? "cannotAmendFixedProperty" : "cannotAssignFixedProperty";
if (classProperty.isConst()) {
errMsg = isAmendsDeclaration ? "cannotAmendConstProperty" : "cannotAssignConstProperty";
}
throw exceptionBuilder()
.evalError(errMsg, memberName)
.withSourceSection(member.getHeaderSection())
.build();
}
}
if (parametersDescriptor != null) {
throw exceptionBuilder()
.evalError("objectAmendmentCannotHaveParameters")
.withLocation(getParentNode())
.build();
}
return true;
}
@SuppressWarnings("SameReturnValue")
@TruffleBoundaryView on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove the override of the fixed property — its value is intentionally immutable
- If you control the base class, change `fixed` to a plain (defaultable) property so amendments can override it
- If you control the base class and the value must never change at all, use `const` semantics consciously — the error will persist either way for `const`
Example fix
// base
class Server { fixed port: Int = 8080 }
// before (amendment)
server { amends Server; port = 9090 }
// after: either delete the override, or in base:
class Server { port: Int = 8080 }
Defensive patterns
Strategy: validation
Validate before calling
// Check the base class for fixed/const on the property you plan to override:
// class Server { fixed port: Int = 8080 } // do not override 'port'
Prevention
- Read the base class declaration before overriding any property
- Treat `fixed`/`const` in upstream modules as off-limits in amendments
- If you own the base, reserve `fixed` only for truly immutable values
When it happens
Trigger: Amending a class whose property is declared `fixed port: Int = 8080` with `port = 9090` in an `amends` literal; the error fires from `SpecializedObjectLiteralNode.checkIsValidTypedAmendment` during amendment validation.
Common situations: Trying to override library defaults that the library author intentionally locked down with `fixed`; copying override blocks between environments where one property is fixed in a newer package version.
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
- wrongFunctionAmendmentParameterCount
- cannotFindPropertyInObject
- listingAmendmentCannotHaveParameters
- mappingAmendmentCannotHaveParameters
- elementIndexOutOfRange
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/0caa6400f291315c.
Report an issue: GitHub.