{"record":{"id":"a17abc87f9e871c9","repo":"apple/pkl","slug":"moduleisnotconst","errorCode":"moduleIsNotConst","errorMessage":"moduleIsNotConst","messagePattern":"moduleIsNotConst","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":646,"sourceCode":"            .build();\n      }\n    }\n    return new OuterNode(createSourceSection(expr));\n  }\n\n  @Override\n  public ExpressionNode visitModuleExpr(ModuleExpr expr) {\n    var currentScope = symbolTable.getCurrentScope();\n    // cannot use unqualified `module` in a const context\n    if (currentScope.getConstLevel().isConst() && !(expr.parent() instanceof QualifiedAccessExpr)) {\n      var scope = currentScope;\n      while (scope != null\n          && !(scope instanceof AnnotationScope)\n          && !(scope instanceof ClassScope)) {\n        scope = scope.getParent();\n      }\n      if (scope == null) {\n        throw exceptionBuilder()\n            .evalError(\"moduleIsNotConst\", currentScope.getName().toString())\n            .withSourceSection(createSourceSection(expr))\n            .build();\n      }\n      var messageKey =\n          scope instanceof AnnotationScope ? \"moduleIsNotConstAnnotation\" : \"moduleIsNotConstClass\";\n      throw exceptionBuilder()\n          .evalError(messageKey)\n          .withSourceSection(createSourceSection(expr))\n          .build();\n    }\n    return symbolTable.isInTypeAliasScope\n        ? new GetTypeAliasModuleNode(createSourceSection(expr))\n        : new GetModuleNode(createSourceSection(expr));\n  }\n\n  @Override\n  public ConstantValueNode visitNullLiteralExpr(NullLiteralExpr expr) {","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L628-L664","documentation":"AstBuilder.visitModuleExpr throws 'moduleIsNotConst' when unqualified `module` appears in a const context: the module self-reference is not available as a constant (annotations can't see the module instance). The input at fault is a bare `module` expression in an annotation or other const-level scope.","triggerScenarios":"Thrown at pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:646 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Qualify the reference (e.g. `module.foo`) if permitted, or reference a constant property instead.","Remove the `module` reference from the annotation/const context."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}