{"record":{"id":"c3f7d8c1215bc1ae","repo":"apple/pkl","slug":"abstractmembercannothavebody","errorCode":"abstractMemberCannotHaveBody","errorMessage":"abstractMemberCannotHaveBody","messagePattern":"abstractMemberCannotHaveBody","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":2163,"sourceCode":"    var annotations = doVisitAnnotations(entry.getAnnotations(), methodName);\n\n    return symbolTable.enterMethod(\n        methodName,\n        getConstLevel(modifiers),\n        bindings,\n        descriptorBuilder,\n        typeParameters,\n        scope -> {\n          ExpressionNode bodyNode;\n          if (bodyContext != null) {\n            if (VmModifier.isExternal(modifiers)) {\n              throw exceptionBuilder()\n                  .evalError(\"externalMemberCannotHaveBody\")\n                  .withSourceSection(headerSection)\n                  .build();\n            }\n            if (VmModifier.isAbstract(modifiers)) {\n              throw exceptionBuilder()\n                  .evalError(\"abstractMemberCannotHaveBody\")\n                  .withSourceSection(headerSection)\n                  .build();\n            }\n            bodyNode = visitExpr(bodyContext);\n          } else {\n            if (VmModifier.isExternal(modifiers)) {\n              bodyNode =\n                  externalMemberRegistry.getFunctionBody(\n                      scope.getQualifiedName(), headerSection, paramCount);\n              if (bodyNode instanceof LanguageAwareNode languageAwareNode) {\n                languageAwareNode.initLanguage(language);\n              }\n            } else if (VmModifier.isAbstract(modifiers)) {\n              bodyNode =\n                  new CannotInvokeAbstractFunctionNode(headerSection, scope.getQualifiedName());\n            } else {\n              throw exceptionBuilder()","sourceCodeStart":2145,"sourceCodeEnd":2181,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L2145-L2181","documentation":"Pkl throws this at build time (AstBuilder) when a class or object member is declared `abstract` but also has a body. Abstract members are placeholders that subclasses must implement; they cannot carry an implementation. The parser-built AST rejects this combination while visiting the member's header/body.","triggerScenarios":"Declaring a member inside a class (Amends/ClassBody) with both the `abstract` modifier and a non-empty body, e.g. `abstract function foo(): Int = 1` or `abstract x: String = \"a\"`. The check fires in the branch where the body exists and `VmModifier.isAbstract(modifiers)` is true.","commonSituations":"Converting a concrete member to abstract (adding `abstract`) without deleting its body; copy-pasting a member and adding `abstract` to satisfy an overridden contract; misunderstanding Pkl's abstract semantics compared to Java interfaces.","solutions":["Remove the `= body` / method body so the member is a pure abstract declaration.","Or remove the `abstract` modifier if the member should keep its implementation.","If the intent was a default that subclasses override, declare it normally (no modifier) instead of abstract."],"exampleFix":"// before\nabstract function endpoint(): String = \"https://api.example.com\"\n// after\nabstract function endpoint(): String","handlingStrategy":"validation","validationCode":"// before compiling, scan member declarations\nfunction hasAbstractWithBody(member) {\n  return member.modifiers.includes('abstract') && member.body != null;\n}\nif (members.some(hasAbstractWithBody)) throw new Error('abstract member must not have a body');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat `abstract` as a signature-only declaration — never write `=` after it.","Review diffs that add the `abstract` modifier for leftover bodies.","Use pkl format/lint tooling in CI to catch this before evaluation."],"tags":["pkl","ast-builder","abstract-member","compile-error"],"backgroundTag":"abstract-member-with-body","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"}