apple/pkl · error
cannotApplyFixedModifier
cannotApplyFixedModifier
Error message
cannotApplyFixedModifier
What it means
Pkl throws cannotApplyFixedModifier when an overriding property adds the `fixed` modifier that the overridden superclass property does not have. UnresolvedPropertyNode.checkOverride detects the mismatch, locates the `fixed` token inside the property header, and raises the error against that exact span. Applying `fixed` during an override would retroactively restrict a property the superclass declared mutable, so it is forbidden.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/member/UnresolvedPropertyNode.java:112
}
var isFixed = VmModifier.isFixed(modifiers);
if (superProperty.isFixed() == isFixed) {
return;
}
CompilerDirectives.transferToInterpreter();
if (superProperty.isFixed()) {
throw exceptionBuilder()
.withSourceSection(headerSection)
.evalError(
"missingFixedModifier",
name,
superClass.getQualifiedName(),
sourceSection.getCharacters())
.build();
}
var source = headerSection.getCharacters().toString();
var fixedModifierIdx = source.indexOf("fixed");
throw exceptionBuilder()
.withSourceSection(
headerSection
.getSource()
.createSection(headerSection.getCharIndex() + fixedModifierIdx, 5))
.evalError("cannotApplyFixedModifier", name, superClass.getQualifiedName())
.build();
}
private void checkConst(VmClass clazz) {
var superClass = clazz.getSuperclass();
if (superClass == null) {
return;
}
var superProperty = superClass.getProperty(name);
if (superProperty == null) {
return;
}
var isConst = VmModifier.isConst(modifiers);View on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove the `fixed` modifier from the overriding property.
- If immutability is required, add `fixed` in the superclass declaration instead, then mirror it in overrides.
- Keep override modifiers identical to the superclass property's modifiers.
- Update the code generator to copy modifiers from the base rather than always emitting `fixed`.
Example fix
// before
class Server extends Base { // Base.name is not fixed
fixed name: String = "mine"
}
// after
class Server extends Base {
name: String = "mine"
} Defensive patterns
Strategy: validation
Validate before calling
// Before adding `fixed` to an override, verify the superclass property is not non-fixed: // Base declares: `name: String` (no fixed) -> override must not add `fixed`.
Prevention
- Never widen restrictions on override; modifiers must match the superclass exactly.
- If immutability is wanted, declare `fixed` in the base class, not the subclass.
- Avoid blanket 'add fixed everywhere' refactors on subclass properties.
- Keep override declarations minimal — omit properties you do not need to change.
When it happens
Trigger: Writing `fixed` on an override whose superclass property is not fixed; tightening a property to fixed in a subclass to prevent later amendment; adding fixed modifiers in bulk during a refactor without checking the base class.
Common situations: Attempting to lock down inherited properties for safety and discovering Pkl forbids narrowing modifiers on override; generated code that stamps `fixed` on all properties; migrating a standalone class into a subclass hierarchy.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- missingFixedModifier
- missingConstModifier
- cannotExtendExternalClass
- noImplementationForAbstractMethod
- noImplementationForAbstractMethods
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/3ab662d9785dba4a.
Report an issue: GitHub.