{"record":{"id":"ba1ecd6497392fb5","repo":"apple/pkl","slug":"methodmustbeconst-ba1ecd","errorCode":"methodMustBeConst","errorMessage":"Cannot call method `{0}` from here because it is not `const`.","messagePattern":"Cannot call method `(.+?)` from here because it is not `const`\\.","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/member/InvokeQualifiedObjectMethodNode.java","lineNumber":49,"sourceCode":"      ExpressionNode[] argumentNodes,\n      boolean needsConst,\n      ExpressionNode getReceiverNode,\n      boolean argsRequireInference) {\n    super(\n        sourceSection,\n        methodName,\n        argumentNodes,\n        needsConst,\n        getReceiverNode,\n        argsRequireInference);\n  }\n\n  @Override\n  protected void doCheckConst(VmObjectLike owner) {\n    var member = owner.getMember(methodName);\n    assert member != null;\n    if (!VmModifier.isConst(member.getModifiers())) {\n      throw exceptionBuilder().evalError(\"methodMustBeConst\", methodName).build();\n    }\n  }\n\n  @Override\n  protected Method getMethod(VmObjectLike owner) {\n    var member = owner.getMember(methodName);\n    assert member != null && member.isLocal();\n    var method = (ObjectMethodNode) member.getMemberNode();\n    assert method != null;\n    return method;\n  }\n}\n","sourceCodeStart":31,"sourceCodeEnd":62,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/member/InvokeQualifiedObjectMethodNode.java#L31-L62","documentation":"Qualified calls to object methods are checked by InvokeQualifiedObjectMethodNode.doCheckConst: the member is fetched via owner.getMember(methodName) and if VmModifier.isConst(member.getModifiers()) is false in a const-requiring call site, this error is thrown.","triggerScenarios":"`obj.method()` (qualified object method call) evaluated where a constant is required and the object method lacks the `const` modifier.","commonSituations":"Reading computed values from a module object in a const position; methods defined by third-party modules without const modifiers.","solutions":["Declare the object method `const`","Cache the value in a non-const property and reference that","Inline the constant computation"],"exampleFix":"// before\nmod {\n  function calc() = 2\n}\nconst k = mod.calc()\n// after\nmod {\n  const function calc() = 2\n}","handlingStrategy":"validation","validationCode":"// ensure the object method is const before qualified const-context calls:\n// const function calc() = 2","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mark pure object methods `const` at definition time","Reference const properties instead of calling methods in const positions","Review third-party modules for const method availability"],"tags":["pkl","const","method-call"],"backgroundTag":"method-not-const","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"}