{"record":{"id":"c0a1873825b3bad7","repo":"apple/pkl","slug":"cannotinvokesupermethodfromhere","errorCode":"cannotInvokeSupermethodFromHere","errorMessage":"cannotInvokeSupermethodFromHere","messagePattern":"cannotInvokeSupermethodFromHere","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":1160,"sourceCode":"  @Override\n  public ExpressionNode visitAmendsExpr(AmendsExpr expr) {\n    // parentExpr is always New, Amends or Parenthesized. The parser makes sure of it in\n    // `Parser.parseExprRest`\n    return doVisitObjectBody(expr.getBody(), visitExpr(expr.getExpr()));\n  }\n\n  @Override\n  public ExpressionNode visitSuperAccessExpr(SuperAccessExpr expr) {\n    var sourceSection = createSourceSection(expr);\n    var memberName = toIdentifier(expr.getIdentifier().getValue());\n    var argCtx = expr.getArgumentList();\n    var currentScope = symbolTable.getCurrentScope();\n    var needsConst =\n        currentScope.getConstLevel() == ConstLevel.ALL && currentScope.getConstDepth() == -1;\n\n    if (argCtx != null) { // supermethod call\n      if (!symbolTable.getCurrentScope().isClassMemberScope()) {\n        throw exceptionBuilder()\n            .evalError(\"cannotInvokeSupermethodFromHere\")\n            .withSourceSection(sourceSection)\n            .build();\n      }\n\n      var argInfo = visitArgumentList(argCtx);\n      return InvokeSuperMethodNodeGen.create(\n          sourceSection, memberName, argInfo.getFirst(), needsConst, argInfo.getSecond());\n    }\n\n    // superproperty call\n    return new ReadSuperPropertyNode(createSourceSection(expr), memberName, needsConst);\n  }\n\n  @Override\n  public ExpressionNode visitSuperSubscriptExpr(SuperSubscriptExpr expr) {\n    return new ReadSuperEntryNode(createSourceSection(expr), visitExpr(expr.getArg()));\n  }","sourceCodeStart":1142,"sourceCodeEnd":1178,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L1142-L1178","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasting a `super.` call from a class into an object literal, or misunderstanding that Pkl object members are not class members.","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."],"exampleFix":"// before (inside object literal)\nfoo { x = super.x + 1 }\n// after (in a class)\nclass A extends B { x = super.x + 1 }","handlingStrategy":"validation","validationCode":"// Only call super.foo(...) inside class member scopes:\nclass A extends B {\n  foo(): Int = super.foo() + 1 // OK\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember `super.` dispatch exists only in class members, not object literals or module properties.","Review copy-pasted `super.` calls after moving code between scopes."],"tags":["pkl","super","class"],"backgroundTag":"unsupported-operation","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"}