apple/pkl · error · VmException

mappingAmendmentCannotHaveParameters

mappingAmendmentCannotHaveParameters

Error message

Expected a function that returns a `Mapping`, but got a `Mapping`.

What it means

An amendment applied to a Mapping must not declare parameters. If the target already is a Mapping (not a function returning one), `(param) -> ...` amendment syntax is rejected by `checkMappingCannotHaveParameters`.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorObjectLiteralNode.java:259

  }

  @Idempotent
  protected boolean checkListingCannotHaveParameters() {
    if (parametersDescriptor == null) return true;

    CompilerDirectives.transferToInterpreter();
    throw exceptionBuilder()
        .evalError("listingAmendmentCannotHaveParameters")
        .withLocation(getParentNode())
        .build();
  }

  @Idempotent
  protected boolean checkMappingCannotHaveParameters() {
    if (parametersDescriptor == null) return true;

    CompilerDirectives.transferToInterpreter();
    throw exceptionBuilder()
        .evalError("mappingAmendmentCannotHaveParameters")
        .withLocation(getParentNode())
        .build();
  }

  @ExplodeLoop
  private ObjectData executeChildren(VirtualFrame frame, Object parent, int parentLength) {
    var data = new ObjectData(parentLength);
    for (var memberNode : memberNodes) {
      memberNode.execute(frame, parent, data);
    }
    return data;
  }
}

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Remove the parameters and write entry amendments keyed explicitly (`someMapping { ["k"] { ... } }`).
  2. Use `for (key, value in someMapping)` generators to transform entries instead of amendment parameters.
  3. If the value is a function returning a Mapping, call it with arguments first, then amend.

Example fix

// before
envs { (name) ->
  [name] { replicas = 2 }
}
// after
envs {
  ["prod"] { replicas = 2 }
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: `someMapping { (key) -> ... }` where `someMapping` is already a Mapping value; parametersDescriptor non-null while the parent resolves to a Mapping instance.

Common situations: Assuming Mapping amendments take a key parameter like `each`/`map` callbacks; copying a function-returned-Mapping pattern onto a plain Mapping property; IDE autocomplete adding parameter braces incorrectly.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


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