apple/pkl · error

missingConstModifier

missingConstModifier

Error message

missingConstModifier

What it means

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.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/member/UnresolvedPropertyNode.java:137

  }

  private void checkConst(VmClass clazz) {
    var superClass = clazz.getSuperclass();
    if (superClass == null) {
      return;
    }
    var superProperty = superClass.getProperty(name);
    if (superProperty == null) {
      return;
    }
    var isConst = VmModifier.isConst(modifiers);
    if (superProperty.isConst() == isConst) {
      return;
    }
    CompilerDirectives.transferToInterpreter();

    if (superProperty.isConst()) {
      throw exceptionBuilder()
          .withSourceSection(headerSection)
          .evalError(
              "missingConstModifier",
              name,
              superClass.getQualifiedName(),
              sourceSection.getCharacters())
          .build();
    }
    var source = headerSection.getCharacters().toString();
    var constModifierIdx = source.indexOf("const");
    throw exceptionBuilder()
        .withSourceSection(
            headerSection
                .getSource()
                .createSection(headerSection.getCharIndex() + constModifierIdx, 5))
        .evalError("cannotApplyConstModifier", name, superClass.getQualifiedName())
        .build();
  }

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Add the `const` modifier to the overriding property declaration.
  2. Alternatively, remove the override and inherit the superclass's const value.
  3. Mirror all superclass property modifiers exactly when overriding.
  4. Audit subclass overrides after any dependency upgrade that changes modifiers.

Example fix

// before
class Server extends Base {
  version: String = "1.0"  // Base.version is const
}

// after
class Server extends Base {
  const version: String = "1.0"
}
Defensive patterns

Strategy: validation

Validate before calling

// Before overriding, check the superclass declaration:
// Base declares: `const version: String` -> your override must also be `const`.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/8be1bc1bb88858ff. Report an issue: GitHub.