{"record":{"id":"a860c485d98d1e13","repo":"apple/pkl","slug":"externalmembercannothavebody","errorCode":"externalMemberCannotHaveBody","errorMessage":"externalMemberCannotHaveBody","messagePattern":"externalMemberCannotHaveBody","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":2070,"sourceCode":"    var fullModifiers =\n        doVisitModifiers(\n            modifierList, VmModifier.VALID_PROPERTY_MODIFIERS, \"invalidPropertyModifier\");\n    // for compat, properties may be abstract, but ignore this\n    var modifiers = fullModifiers & ~VmModifier.ABSTRACT;\n\n    var isLocal = VmModifier.isLocal(modifiers);\n    var propertyName = org.pkl.core.runtime.Identifier.property(name.getValue(), isLocal);\n    var annotationNodes = doVisitAnnotations(annotations, propertyName);\n\n    return symbolTable.enterProperty(\n        propertyName,\n        getConstLevel(modifiers),\n        scope -> {\n          ExpressionNode bodyNode;\n\n          if (expr != null) { // prop = expr\n            if (VmModifier.isExternal(modifiers)) {\n              throw exceptionBuilder()\n                  .evalError(\"externalMemberCannotHaveBody\")\n                  .withSourceSection(headerSection)\n                  .build();\n            }\n            bodyNode = visitExpr(expr);\n          } else if (!objectBodies.isEmpty()) { // prop { ... }\n            if (typeAnnotation != null) {\n              throw exceptionBuilder()\n                  .evalError(\"cannotAmendPropertyDefinition\")\n                  .withSourceSection(createSourceSection(entry))\n                  .build();\n            }\n            bodyNode =\n                doVisitObjectBody(\n                    objectBodies,\n                    new ReadSuperPropertyNode(\n                        unavailableSourceSection(),\n                        scope.getName(),","sourceCodeStart":2052,"sourceCodeEnd":2088,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L2052-L2088","documentation":"A property marked `external` declares its implementation is provided by the host (via externalMemberRegistry) and must not have an inline body. AstBuilder throws externalMemberCannotHaveBody when an external property definition also has `prop = expr`, pointing at the header section.","triggerScenarios":"Writing `external prop: Type = expr` — i.e. VmModifier.isExternal(modifiers) is true while an expr body is present — during property AST construction.","commonSituations":"Defining properties that mirror built-in external members of pkl.base modules; hand-writing module code that mimics stdlib declarations; migrating a property from normal to external while leaving its body.","solutions":["Remove the `external` modifier and keep the body.","Remove the `= expr` body and keep `external`, registering the implementation in the ExternalMemberRegistry.","Check whether you meant `abstract` (body-less, subclass provides) rather than `external`."],"exampleFix":"// before\nexternal prop: Int = 42\n\n// after\nprop: Int = 42","handlingStrategy":"validation","validationCode":"// Ensure external properties have no inline body:\nif (hasModifier(prop, \"external\") && prop.hasValueExpression()) {\n  report(prop, \"external properties cannot have a body\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only mark a property `external` when you also register its implementation with the ExternalMemberRegistry.","External declarations are for host-provided members; user modules rarely need them.","If you want a body-less method for subclasses, use `abstract`, not `external`."],"tags":["pkl","ast","external","property"],"backgroundTag":"invalid-argument-value","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"}