apple/pkl · error · VmException
cannotFindMethodInScope
cannotFindMethodInScope
Error message
Cannot find method `{0}`. What it means
Thrown when a `super.method(...)` invocation cannot locate the named method on any superclass of the enclosing class. After walking past VmFunction owners to the enclosing prototype, `findSupermethod` queries `superclass.getMethod(...)`; if the lookup returns null, Pkl reports that the method cannot be found in scope, anchored at the enclosing definition's parent. This is essentially a super-call to a method that does not exist in the inheritance chain.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/member/InvokeSuperMethodNode.java:82
assert owner.isPrototype();
var superclass = owner.getVmClass().getSuperclass();
assert superclass != null;
// note the use of getMethod() rather than getDeclaredMethod()
var supermethod = superclass.getMethod(methodName);
if (supermethod != null) {
if (needsConst && !supermethod.isConst()) {
CompilerDirectives.transferToInterpreter();
throw exceptionBuilder().evalError("methodMustBeConst", methodName.toString()).build();
}
return supermethod;
}
CompilerDirectives.transferToInterpreter();
var parent = owner.getParent();
assert parent != null;
throw exceptionBuilder()
.cannotFindMethod(parent, methodName, argumentNodes.length, false)
.build();
}
}
View on GitHub (pinned to f3efcbfc9b)
Solutions
- Check the superclass chain (via `getClass().getSuperclass()` semantics) and confirm a method with that exact name and arity exists; fix the call site name or add the missing method to the superclass.
- If the method exists only on the current class, call it directly instead of via `super`.
- If it is a property, not a method, read it without call parentheses or override the intended method.
- If a parent-class rename caused it, update all `super.oldName()` calls to the new name.
Example fix
// before
open class Base {
function describe(): String = "base"
}
class Child extends Base {
function describe(): String = super.toString2() // error: no such method on Base
}
// after
open class Base {
function describe(): String = "base"
}
class Child extends Base {
function describe(): String = super.describe() + " child"
} Defensive patterns
Strategy: validation
Validate before calling
// Pkl: check the method exists on the superclass chain before a super call function hasSuperMethod(cls: Class, name: String): Boolean = cls.getSuperclass()?.getMethod(name) != null
Prevention
- Keep subclass `super.x()` calls in sync with base-class declarations; update all call sites when renaming.
- Only use `super` for methods actually declared on a superclass, not local methods or properties.
- Run `pkl test` or evaluate modules in CI so missing super-method calls fail at build time.
When it happens
Trigger: Occurs when `super.foo(...)` is written in a class whose superclass chain contains no method named `foo` (the method was never declared, is declared only in the subclass itself, or is a property rather than a method). Also fires when the method name is misspelled or renamed in the parent after a refactor.
Common situations: Renaming or removing a method in a base class while subclasses still call it via `super`; copy-pasting a subclass template that references a super method the parent never had; confusing properties with methods (calling `super.someProp()` when `someProp` is a property); targeting the wrong parent class after changing `extends`.
Related errors
- cannotExtendExternalClass
- noImplementationForAbstractMethod
- noImplementationForAbstractMethods
- invalidSupertype
- methodMustBeConst
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/77c7b4ede2ae27d5.
Report an issue: GitHub.