apple/pkl · error · VmException
cannotInvokeSupermethodFromHere
cannotInvokeSupermethodFromHere
Error message
cannotInvokeSupermethodFromHere
What it means
Supermethod calls (`super.foo(...)` with arguments) are only legal inside class member scopes. If the builder sees a supermethod call while the current scope is not a class member (e.g. object member, function, module property), it throws cannotInvokeSupermethodFromHere because there is no superclass dispatch target.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:1160
@Override
public ExpressionNode visitAmendsExpr(AmendsExpr expr) {
// parentExpr is always New, Amends or Parenthesized. The parser makes sure of it in
// `Parser.parseExprRest`
return doVisitObjectBody(expr.getBody(), visitExpr(expr.getExpr()));
}
@Override
public ExpressionNode visitSuperAccessExpr(SuperAccessExpr expr) {
var sourceSection = createSourceSection(expr);
var memberName = toIdentifier(expr.getIdentifier().getValue());
var argCtx = expr.getArgumentList();
var currentScope = symbolTable.getCurrentScope();
var needsConst =
currentScope.getConstLevel() == ConstLevel.ALL && currentScope.getConstDepth() == -1;
if (argCtx != null) { // supermethod call
if (!symbolTable.getCurrentScope().isClassMemberScope()) {
throw exceptionBuilder()
.evalError("cannotInvokeSupermethodFromHere")
.withSourceSection(sourceSection)
.build();
}
var argInfo = visitArgumentList(argCtx);
return InvokeSuperMethodNodeGen.create(
sourceSection, memberName, argInfo.getFirst(), needsConst, argInfo.getSecond());
}
// superproperty call
return new ReadSuperPropertyNode(createSourceSection(expr), memberName, needsConst);
}
@Override
public ExpressionNode visitSuperSubscriptExpr(SuperSubscriptExpr expr) {
return new ReadSuperEntryNode(createSourceSection(expr), visitExpr(expr.getArg()));
}View on GitHub (pinned to f3efcbfc9b)
Solutions
- Move the supermethod call into a class member (method or property override) of a class that extends a parent with the method.
- If inside an object literal, drop the `super.` call — object amending overrides properties, not class method dispatch.
- Call the parent's behavior indirectly, e.g. via a helper function or by referencing the base implementation explicitly.
Example fix
// before (inside object literal)
foo { x = super.x + 1 }
// after (in a class)
class A extends B { x = super.x + 1 } Defensive patterns
Strategy: validation
Validate before calling
// Only call super.foo(...) inside class member scopes:
class A extends B {
foo(): Int = super.foo() + 1 // OK
} Prevention
- Remember `super.` dispatch exists only in class members, not object literals or module properties.
- Review copy-pasted `super.` calls after moving code between scopes.
When it happens
Trigger: Calling `super.method(args)` from a module-level property, an object body (amending literal), a lambda, or a standalone function rather than from a class method or property override.
Common situations: Copy-pasting a `super.` call from a class into an object literal, or misunderstanding that Pkl object members are not class members.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Values of type `Class` cannot be rendered as YAML. Value: %s
- cannotInstantiateAbstractClass
- cannotInstantiateExternalClass
- expectedAnnotationClass
- propertyMustBeConst
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/c0a1873825b3bad7.
Report an issue: GitHub.