{"record":{"id":"3ab662d9785dba4a","repo":"apple/pkl","slug":"cannotapplyfixedmodifier","errorCode":"cannotApplyFixedModifier","errorMessage":"cannotApplyFixedModifier","messagePattern":"cannotApplyFixedModifier","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/member/UnresolvedPropertyNode.java","lineNumber":112,"sourceCode":"    }\n    var isFixed = VmModifier.isFixed(modifiers);\n    if (superProperty.isFixed() == isFixed) {\n      return;\n    }\n    CompilerDirectives.transferToInterpreter();\n    if (superProperty.isFixed()) {\n      throw exceptionBuilder()\n          .withSourceSection(headerSection)\n          .evalError(\n              \"missingFixedModifier\",\n              name,\n              superClass.getQualifiedName(),\n              sourceSection.getCharacters())\n          .build();\n    }\n    var source = headerSection.getCharacters().toString();\n    var fixedModifierIdx = source.indexOf(\"fixed\");\n    throw exceptionBuilder()\n        .withSourceSection(\n            headerSection\n                .getSource()\n                .createSection(headerSection.getCharIndex() + fixedModifierIdx, 5))\n        .evalError(\"cannotApplyFixedModifier\", name, superClass.getQualifiedName())\n        .build();\n  }\n\n  private void checkConst(VmClass clazz) {\n    var superClass = clazz.getSuperclass();\n    if (superClass == null) {\n      return;\n    }\n    var superProperty = superClass.getProperty(name);\n    if (superProperty == null) {\n      return;\n    }\n    var isConst = VmModifier.isConst(modifiers);","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/member/UnresolvedPropertyNode.java#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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`."],"exampleFix":"// before\nclass Server extends Base {  // Base.name is not fixed\n  fixed name: String = \"mine\"\n}\n\n// after\nclass Server extends Base {\n  name: String = \"mine\"\n}","handlingStrategy":"validation","validationCode":"// Before adding `fixed` to an override, verify the superclass property is not non-fixed:\n// Base declares: `name: String` (no fixed) -> override must not add `fixed`.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["pkl","override","fixed-modifier","inheritance"],"backgroundTag":"conflicting-config-options","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}