apple/pkl · error · VmException

nonLocalObjectPropertyCannotHaveTypeAnnotation

nonLocalObjectPropertyCannotHaveTypeAnnotation

Error message

nonLocalObjectPropertyCannotHaveTypeAnnotation

What it means

Non-local object properties in an amendment cannot carry type annotations, because a type annotation implies defining (not just amending) the property's type. AstBuilder throws nonLocalObjectPropertyCannotHaveTypeAnnotation when isAmend(), the member is not local, and ctx.getTypeAnnotation() != null; the error points at the annotation's type.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:1814

            .build();
      }

      checkDuplicateMember(member.getName(), member.getHeaderSection(), propertyNames);
      EconomicMaps.put(result, member.getName(), member);
    }

    for (var ctx : properties) {
      var member =
          doVisitObjectProperty(
              ctx,
              ctx.getModifiers(),
              ctx.getName(),
              ctx.getTypeAnnotation(),
              ctx.getExpr(),
              ctx.getBodyList());

      if (moduleInfo.isAmend() && !member.isLocal() && ctx.getTypeAnnotation() != null) {
        throw exceptionBuilder()
            .evalError("nonLocalObjectPropertyCannotHaveTypeAnnotation")
            .withSourceSection(createSourceSection(ctx.getTypeAnnotation().getType()))
            .build();
      }

      checkDuplicateMember(member.getName(), member.getHeaderSection(), propertyNames);
      EconomicMaps.put(result, member.getName(), member);
    }

    return result;
  }

  @Override
  public ObjectMember visitImportClause(ImportClause imp) {
    var importNode = doVisitImport(imp.isGlob(), imp, imp.getImportStr());
    var moduleKey = moduleResolver.resolve(importNode.getImportUri());
    var importName =
        org.pkl.core.runtime.Identifier.property(

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Remove the type annotation from the amended property (`prop { ... }` instead of `prop: Type { ... }`).
  2. Mark the property `local` if you actually want a fresh definition.
  3. Declare the property with its type in the base module and amend only its value.

Example fix

// before (in an amendment)
server: Server { port = 8080 }

// after
server { port = 8080 }
Defensive patterns

Strategy: validation

Validate before calling

// Detect typed property definitions inside amendment files:
if (isAmendmentFile(file) && line.matches("\\s*\\w+\\s*:\\s*\\w+.*")) {
  report(file, lineNo, "amended properties cannot carry type annotations");
}

Prevention

When it happens

Trigger: In an amendment or object body being amended, writing `propName: Type { ... }` or `propName: Type = ...` where prop is non-local and has a type annotation.

Common situations: Copy-pasting property definitions with type annotations from a base module into an override/amendment file; tightening types while overriding a property in a layered config.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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