{"record":{"id":"8be1bc1bb88858ff","repo":"apple/pkl","slug":"missingconstmodifier","errorCode":"missingConstModifier","errorMessage":"missingConstModifier","messagePattern":"missingConstModifier","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/member/UnresolvedPropertyNode.java","lineNumber":137,"sourceCode":"  }\n\n  private void checkConst(VmClass clazz) {\n    var superClass = clazz.getSuperclass();\n    if (superClass == null) {\n      return;\n    }\n    var superProperty = superClass.getProperty(name);\n    if (superProperty == null) {\n      return;\n    }\n    var isConst = VmModifier.isConst(modifiers);\n    if (superProperty.isConst() == isConst) {\n      return;\n    }\n    CompilerDirectives.transferToInterpreter();\n\n    if (superProperty.isConst()) {\n      throw exceptionBuilder()\n          .withSourceSection(headerSection)\n          .evalError(\n              \"missingConstModifier\",\n              name,\n              superClass.getQualifiedName(),\n              sourceSection.getCharacters())\n          .build();\n    }\n    var source = headerSection.getCharacters().toString();\n    var constModifierIdx = source.indexOf(\"const\");\n    throw exceptionBuilder()\n        .withSourceSection(\n            headerSection\n                .getSource()\n                .createSection(headerSection.getCharIndex() + constModifierIdx, 5))\n        .evalError(\"cannotApplyConstModifier\", name, superClass.getQualifiedName())\n        .build();\n  }","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/member/UnresolvedPropertyNode.java#L119-L155","documentation":"Pkl throws missingConstModifier when an overriding property is `const` in the superclass but the override omits the `const` modifier. UnresolvedPropertyNode.checkConst enforces modifier parity between a property and its overridden superclass property, because a const (compile-time-computable) property cannot be weakened to a non-const override. The error names the property, the superclass's qualified name, and the offending source text.","triggerScenarios":"Overriding a `const` property from a base class/module without `const` on the override; a base property becomes const in a newer package version while overrides lack the modifier; copying overrides from non-const siblings.","commonSituations":"Library upgrade converts properties to const for caching/analysis, breaking subclass overrides; hand-written overrides missing modifier parity; code generation not propagating const from the base class.","solutions":["Add the `const` modifier to the overriding property declaration.","Alternatively, remove the override and inherit the superclass's const value.","Mirror all superclass property modifiers exactly when overriding.","Audit subclass overrides after any dependency upgrade that changes modifiers."],"exampleFix":"// before\nclass Server extends Base {\n  version: String = \"1.0\"  // Base.version is const\n}\n\n// after\nclass Server extends Base {\n  const version: String = \"1.0\"\n}","handlingStrategy":"validation","validationCode":"// Before overriding, check the superclass declaration:\n// Base declares: `const version: String` -> your override must also be `const`.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mirror const/fixed modifiers from the superclass on every override.","After upgrading a package, grep subclasses for overrides of properties that became const.","Prefer inheriting const values over re-declaring them.","Run pkl eval/tests in CI so modifier mismatches fail fast."],"tags":["pkl","override","const-modifier","inheritance"],"backgroundTag":"conflicting-config-options","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"}