{"record":{"id":"baa7b2bd186e3d01","repo":"apple/pkl","slug":"thisisnotconst","errorCode":"thisIsNotConst","errorMessage":"thisIsNotConst","messagePattern":"thisIsNotConst","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":606,"sourceCode":"    var pars = new UnresolvedTypeNode[type.getArgs().size()];\n    for (int i = 0; i < pars.length; i++) {\n      pars[i] = visitType(type.getArgs().get(i));\n    }\n\n    return new UnresolvedTypeNode.Function(\n        createSourceSection(type), pars, visitType(type.getRet()));\n  }\n\n  @Override\n  public ExpressionNode visitThisExpr(ThisExpr expr) {\n    if (!(expr.parent() instanceof QualifiedAccessExpr)) {\n      var currentScope = symbolTable.getCurrentScope();\n      var needsConst =\n          currentScope.getConstLevel() == ConstLevel.ALL\n              && currentScope.getConstDepth() == -1\n              && !currentScope.isCustomThisScope();\n      if (needsConst) {\n        throw exceptionBuilder()\n            .withSourceSection(createSourceSection(expr))\n            .evalError(\"thisIsNotConst\")\n            .build();\n      }\n    }\n    return VmUtils.createThisNode(\n        createSourceSection(expr), symbolTable.getCurrentScope().isCustomThisScope());\n  }\n\n  // TODO: `outer.` should probably have semantics similar to `super.`,\n  // rather than just performing a lookup in the immediately enclosing object\n  // also, consider interpreting `x = ... x ...` as `x = ... outer.x ...`\n  @Override\n  public OuterNode visitOuterExpr(OuterExpr expr) {\n    if (!(expr.parent() instanceof QualifiedAccessExpr)) {\n      var constLevel = symbolTable.getCurrentScope().getConstLevel();\n      var outerScope = getParentLexicalScope();\n      if (outerScope != null && constLevel.bigger(outerScope.getConstLevel())) {","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L588-L624","documentation":"AstBuilder.visitThisExpr throws 'thisIsNotConst' when unqualified `this` appears in a const context (e.g. inside an annotation argument), because const evaluation requires statically fixed values and `this` is not const there. The input at fault is a bare `this` expression used in an annotation/const position.","triggerScenarios":"Thrown at pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:606 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Qualify the access (e.g. `this.foo` on a named receiver) or restructure so no `this` is needed in the const context.","Use a literal or constant value in the annotation instead."],"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"}