{"record":{"id":"0caa6400f291315c","repo":"apple/pkl","slug":"cannotamendfixedproperty","errorCode":"cannotAmendFixedProperty","errorMessage":"Cannot amend fixed property `{0}`.","messagePattern":"Cannot amend fixed property `(.+?)`\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java","lineNumber":98,"sourceCode":"      if (!parentClass.hasProperty(memberName)) {\n        throw exceptionBuilder()\n            .cannotFindProperty(parentClass.getPrototype(), memberName, false, false)\n            .withSourceSection(member.getHeaderSection())\n            .build();\n      }\n      var classProperty = parentClass.getProperty(memberName);\n      if (classProperty != null && classProperty.isConstOrFixed()) {\n        // tailor error message based on whether an amends declaration is used or not\n        // (i.e. `friends {}` vs. `friends = new {}`)\n        // an amends declaration's body section includes the header section, whereas normal property\n        // assignment's body section is the section after the equal sign.\n        var isAmendsDeclaration =\n            member.getHeaderSection().getCharIndex() == member.getBodySection().getCharIndex();\n        var errMsg = isAmendsDeclaration ? \"cannotAmendFixedProperty\" : \"cannotAssignFixedProperty\";\n        if (classProperty.isConst()) {\n          errMsg = isAmendsDeclaration ? \"cannotAmendConstProperty\" : \"cannotAssignConstProperty\";\n        }\n        throw exceptionBuilder()\n            .evalError(errMsg, memberName)\n            .withSourceSection(member.getHeaderSection())\n            .build();\n      }\n    }\n\n    if (parametersDescriptor != null) {\n      throw exceptionBuilder()\n          .evalError(\"objectAmendmentCannotHaveParameters\")\n          .withLocation(getParentNode())\n          .build();\n    }\n\n    return true;\n  }\n\n  @SuppressWarnings(\"SameReturnValue\")\n  @TruffleBoundary","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java#L80-L116","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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`"],"exampleFix":"// base\nclass Server { fixed port: Int = 8080 }\n// before (amendment)\nserver { amends Server; port = 9090 }\n// after: either delete the override, or in base:\nclass Server { port: Int = 8080 }\n","handlingStrategy":"validation","validationCode":"// Check the base class for fixed/const on the property you plan to override:\n// class Server { fixed port: Int = 8080 }  // do not override 'port'\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["pkl","amends","fixed-property","immutability"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}