apple/pkl · error · VmException

wrongFunctionAmendmentParameterCount

wrongFunctionAmendmentParameterCount

Error message

Expected a function with {0} parameters, but got {1}.

What it means

Pkl's `amends` clause lets an object literal amend an existing object or module. When the amended parent is a function that produces the object, the literal's own parameter list must match the parent function's parameter count exactly. `checkIsValidFunctionAmendment` in ObjectLiteralNode throws this error when the amendment declares parameters (length > 0) whose count differs from the parent function's.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/literal/ObjectLiteralNode.java:89

  }

  @Idempotent
  protected static boolean isTypedObjectClass(VmClass clazz) {
    if (clazz.isListingClass()
        || clazz.isMappingClass()
        || clazz.isDynamicClass()
        || clazz.isFunctionClass()
        || clazz.isFunctionNClass()) {
      return false;
    }
    return BaseModule.getTypedClass().isSuperclassOf(clazz);
  }

  protected final boolean checkIsValidFunctionAmendment(VmFunction parent) {
    var length = parameterTypes.length;
    if (length > 0 && length != parent.getParameterCount()) {
      CompilerDirectives.transferToInterpreter();
      throw exceptionBuilder()
          .evalError("wrongFunctionAmendmentParameterCount", length, parent.getParameterCount())
          .withSourceSection(getParentNode().getSourceSection())
          .build();
    }
    return true;
  }

  @Idempotent
  protected final boolean checkIsValidFunctionAmendment(Object parent) {
    return checkIsValidFunctionAmendment((VmFunction) parent);
  }

  @Idempotent
  protected final boolean isFunction(Object value) {
    return value instanceof VmFunction;
  }

  protected final Object getNullDefaultValue(VmNull parent) {

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Count the parameters on the amended parent function and give the amendment's parameter list exactly that many parameters
  2. Remove the parameter list from the amendment entirely if it does not need parameters (an empty/no list is only allowed when the parent also takes none — here length must equal parent count if >0)
  3. Update the parent function signature consistently and fix all amendment sites, or bump versions so amendments are regenerated

Example fix

// before
foo = (x) -> new { ... }
bar { amends foo } // or (a, b) { amends foo }
// after
bar (x) { amends foo } // parameter count matches parent
Defensive patterns

Strategy: validation

Validate before calling

// Pkl: before amending, assert parameter counts line up (mentally or via test)
// function foo(x) { ... }
// amendment must be: bar (x) { amends foo }
// Test in Pkl: validated automatically at eval; keep base and amendments in one module to catch drift.

Prevention

When it happens

Trigger: Declaring `x = (a) { ... } amends someModule` or `foo { ... amends (a, b) -> ... }` where the number of parameters in the amendment's parameter list differs from `parent.getParameterCount()` of the VmFunction being amended.

Common situations: Copy-pasting an `amends` declaration from one module to another whose base object takes a different number of properties; renaming or adding parameters to the base function but forgetting to update every amendment site; converting a zero-arg base to a parameterized one after downstream modules already amend it.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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