apple/pkl · error · VmException
missingMethodBody
missingMethodBody
Error message
missingMethodBody
What it means
Thrown when a function member has neither a body nor the `abstract` modifier. Pkl requires every non-abstract function to implement something; a bare signature is invalid syntax for a concrete function. Abstract functions without bodies are allowed and compile to CannotInvokeAbstractFunctionNode.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:2181
throw exceptionBuilder()
.evalError("abstractMemberCannotHaveBody")
.withSourceSection(headerSection)
.build();
}
bodyNode = visitExpr(bodyContext);
} else {
if (VmModifier.isExternal(modifiers)) {
bodyNode =
externalMemberRegistry.getFunctionBody(
scope.getQualifiedName(), headerSection, paramCount);
if (bodyNode instanceof LanguageAwareNode languageAwareNode) {
languageAwareNode.initLanguage(language);
}
} else if (VmModifier.isAbstract(modifiers)) {
bodyNode =
new CannotInvokeAbstractFunctionNode(headerSection, scope.getQualifiedName());
} else {
throw exceptionBuilder()
.evalError("missingMethodBody", methodName)
.withSourceSection(headerSection)
.build();
}
}
return new UnresolvedMethodNode(
language,
createSourceSection(entry),
headerSection,
scope.buildFrameDescriptor(),
createDocSourceSection(entry.getDocComment()),
annotations,
modifiers,
methodName,
scope.getQualifiedName(),
paramCount,
typeParameters,View on GitHub (pinned to f3efcbfc9b)
Solutions
- Add a body: `function foo(): Int = 42`.
- Or mark the member `abstract` if it must be implemented by subclasses.
- Or remove the declaration entirely if it is unused.
Example fix
// before function render(): String // after abstract function render(): String // or function render(): String = "default"
Defensive patterns
Strategy: validation
Validate before calling
// every function member needs a body or the abstract modifier
function validateFunctionMember(m) {
if (!m.isAbstract && m.body == null)
throw new Error(`function ${m.name} needs a body or 'abstract'`);
} Prevention
- Never leave a function signature without `= expr` or `abstract` when porting interface-style code.
- Grep for `^\s*function .+\(.*\)\s*:\s*\w+\s*$` lines without bodies during refactors.
- Run `pkl eval` on modules in CI to fail fast on incomplete declarations.
When it happens
Trigger: Writing `function foo(): Int` (no `= expr`, no `abstract`) inside a class or module. Fires in the else branch of the body-handling logic where modifiers are not abstract and no bodyNode was produced.
Common situations: Porting Java interface-style declarations into Pkl and forgetting `abstract`; deleting a function body during refactoring; incomplete code generation or templated snippets left unimplemented.
Understand the failure class
Background: "NotImplementedError: Subclasses should override this method" / "must be implemented" — abstract method errors explained — this error's family across 40 libraries.
Related errors
- abstractMemberCannotHaveBody
- cannotDeclareTypeParameter
- duplicateTypeParameter
- invalidTypeName
- invalidConstObjectMemberModifier
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/1e26e59419dc6191.
Report an issue: GitHub.