{"record":{"id":"77c7b4ede2ae27d5","repo":"apple/pkl","slug":"cannotfindmethodinscope-77c7b4","errorCode":"cannotFindMethodInScope","errorMessage":"Cannot find method `{0}`.","messagePattern":"Cannot find method `(.+?)`\\.","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/member/InvokeSuperMethodNode.java","lineNumber":82,"sourceCode":"    assert owner.isPrototype();\n\n    var superclass = owner.getVmClass().getSuperclass();\n    assert superclass != null;\n\n    // note the use of getMethod() rather than getDeclaredMethod()\n    var supermethod = superclass.getMethod(methodName);\n    if (supermethod != null) {\n      if (needsConst && !supermethod.isConst()) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder().evalError(\"methodMustBeConst\", methodName.toString()).build();\n      }\n      return supermethod;\n    }\n\n    CompilerDirectives.transferToInterpreter();\n    var parent = owner.getParent();\n    assert parent != null;\n    throw exceptionBuilder()\n        .cannotFindMethod(parent, methodName, argumentNodes.length, false)\n        .build();\n  }\n}\n","sourceCodeStart":64,"sourceCodeEnd":87,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/member/InvokeSuperMethodNode.java#L64-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"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`.","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."],"exampleFix":"// before\nopen class Base {\n  function describe(): String = \"base\"\n}\nclass Child extends Base {\n  function describe(): String = super.toString2() // error: no such method on Base\n}\n\n// after\nopen class Base {\n  function describe(): String = \"base\"\n}\nclass Child extends Base {\n  function describe(): String = super.describe() + \" child\"\n}","handlingStrategy":"validation","validationCode":"// Pkl: check the method exists on the superclass chain before a super call\nfunction hasSuperMethod(cls: Class, name: String): Boolean =\n  cls.getSuperclass()?.getMethod(name) != null","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["pkl","method-not-found","super-method","inheritance"],"backgroundTag":"method-not-implemented","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"}