{"record":{"id":"bad7ef18a9eff526","repo":"apple/pkl","slug":"nonlocalobjectpropertycannothavetypeannotation","errorCode":"nonLocalObjectPropertyCannotHaveTypeAnnotation","errorMessage":"nonLocalObjectPropertyCannotHaveTypeAnnotation","messagePattern":"nonLocalObjectPropertyCannotHaveTypeAnnotation","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":1814,"sourceCode":"            .build();\n      }\n\n      checkDuplicateMember(member.getName(), member.getHeaderSection(), propertyNames);\n      EconomicMaps.put(result, member.getName(), member);\n    }\n\n    for (var ctx : properties) {\n      var member =\n          doVisitObjectProperty(\n              ctx,\n              ctx.getModifiers(),\n              ctx.getName(),\n              ctx.getTypeAnnotation(),\n              ctx.getExpr(),\n              ctx.getBodyList());\n\n      if (moduleInfo.isAmend() && !member.isLocal() && ctx.getTypeAnnotation() != null) {\n        throw exceptionBuilder()\n            .evalError(\"nonLocalObjectPropertyCannotHaveTypeAnnotation\")\n            .withSourceSection(createSourceSection(ctx.getTypeAnnotation().getType()))\n            .build();\n      }\n\n      checkDuplicateMember(member.getName(), member.getHeaderSection(), propertyNames);\n      EconomicMaps.put(result, member.getName(), member);\n    }\n\n    return result;\n  }\n\n  @Override\n  public ObjectMember visitImportClause(ImportClause imp) {\n    var importNode = doVisitImport(imp.isGlob(), imp, imp.getImportStr());\n    var moduleKey = moduleResolver.resolve(importNode.getImportUri());\n    var importName =\n        org.pkl.core.runtime.Identifier.property(","sourceCodeStart":1796,"sourceCodeEnd":1832,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L1796-L1832","documentation":"Non-local object properties in an amendment cannot carry type annotations, because a type annotation implies defining (not just amending) the property's type. AstBuilder throws nonLocalObjectPropertyCannotHaveTypeAnnotation when isAmend(), the member is not local, and ctx.getTypeAnnotation() != null; the error points at the annotation's type.","triggerScenarios":"In an amendment or object body being amended, writing `propName: Type { ... }` or `propName: Type = ...` where prop is non-local and has a type annotation.","commonSituations":"Copy-pasting property definitions with type annotations from a base module into an override/amendment file; tightening types while overriding a property in a layered config.","solutions":["Remove the type annotation from the amended property (`prop { ... }` instead of `prop: Type { ... }`).","Mark the property `local` if you actually want a fresh definition.","Declare the property with its type in the base module and amend only its value."],"exampleFix":"// before (in an amendment)\nserver: Server { port = 8080 }\n\n// after\nserver { port = 8080 }","handlingStrategy":"validation","validationCode":"// Detect typed property definitions inside amendment files:\nif (isAmendmentFile(file) && line.matches(\"\\\\s*\\\\w+\\\\s*:\\\\s*\\\\w+.*\")) {\n  report(file, lineNo, \"amended properties cannot carry type annotations\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare property types once in the base module; amend values only.","When copying property definitions into amendments, strip the `: Type` part.","Use `local` explicitly when a genuinely new typed property is intended."],"tags":["pkl","ast","amendment","type-annotation"],"backgroundTag":"invalid-config-value","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"}