{"record":{"id":"766c158cf5d42ba3","repo":"apple/pkl","slug":"cannotamendlocalpropertydefinition","errorCode":"cannotAmendLocalPropertyDefinition","errorMessage":"cannotAmendLocalPropertyDefinition","messagePattern":"cannotAmendLocalPropertyDefinition","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":2689,"sourceCode":"        scope -> {\n          if (isLocal) {\n            if (expr == null\n                && typeAnn != null) { // module property that has type annotation but no value\n              throw missingLocalPropertyValue(typeAnn);\n            }\n          } else {\n            if (typeAnn != null) {\n              throw exceptionBuilder()\n                  .evalError(\"nonLocalObjectPropertyCannotHaveTypeAnnotation\")\n                  .withSourceSection(createSourceSection(typeAnn.getType()))\n                  .build();\n            }\n          }\n\n          ExpressionNode bodyNode;\n          if (body != null && !body.isEmpty()) { // foo { ... }\n            if (isLocal) {\n              throw exceptionBuilder()\n                  .evalError(\"cannotAmendLocalPropertyDefinition\")\n                  .withSourceSection(createSourceSection(body.get(0)))\n                  .build();\n            }\n            bodyNode =\n                doVisitObjectBody(\n                    body,\n                    new ReadSuperPropertyNode(\n                        unavailableSourceSection(),\n                        scope.getName(),\n                        // Never need a const check for amends declarations. In `foo { ... }`:\n                        // 1. if `foo` is const, i.e. `const foo { ... }`, `super.foo` is required\n                        // to be const (the const-ness of a property cannot be changed)\n                        // 2. if in a const scope (i.e. `const bar = new { foo { ... } }`),\n                        // `super.foo` does not reference something outside the scope.\n                        false));\n          } else { // foo = ...\n            assert expr != null;","sourceCodeStart":2671,"sourceCodeEnd":2707,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L2671-L2707","documentation":"Pkl throws `cannotAmendLocalPropertyDefinition` when an object body (`{ ... }`) follows a local property definition. Local properties are per-object bindings that cannot be amended by an object body; only regular (non-local) properties support amendment. AstBuilder detects `isLocal` combined with a non-empty body and fails at build time.","triggerScenarios":"Declaring `local foo = 1 { ... }` or `local foo { ... }` inside an object/class body — i.e. a local modifier plus an object-body block in AstBuilder's object member visitation (file pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:2689).","commonSituations":"Developers converting a regular property to `local` to hide it from output but forgetting it had an amend body; copy-pasting object bodies onto local helper bindings; refactoring amending properties into locals.","solutions":["Remove the `{ ... }` object body from the local property declaration.","If amendment is needed, drop the `local` modifier and use a regular (possibly `hidden`) property.","Assign the extra content as additional local properties instead of amending one local."],"exampleFix":"// before\nlocal base = 1 {\n  extra = 2\n}\n// after\nlocal base = 1\nlocal extra = 2\n// or: base = 1 { extra = 2 } without `local`","handlingStrategy":"validation","validationCode":"// pkl test / pkl eval catches this at parse time\n// grep check: local property followed by '{'\nif (/local\\s+[a-zA-Z_]\\w*\\s*=(\\s|\\S)*\\{/.test(pklSource)) {\n  throw new Error(\"local property must not have an amend body\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember: `local` and amendment bodies are mutually exclusive.","Run `pkl eval` in CI so syntax-level errors surface before deploy.","Convert to `hidden` instead of `local` when you still need an amend body."],"tags":["pkl","parser","object-member","local-property"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}