apple/pkl · error · VmException

listingAmendmentCannotHaveParameters

listingAmendmentCannotHaveParameters

Error message

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

What it means

An amendment applied to a Listing must not declare parameters. If the target already is a Listing (not a function returning a Listing), supplying `(param) -> ...` amendment syntax is invalid and rejected by `checkListingCannotHaveParameters`.

Source

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

  }

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

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

  @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) {

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Drop the parameter list and amend the Listing entries directly (`someListing { ... { ... } }`).
  2. If element-wise transformation is needed, use `for` generators or `map` on the Listing instead of amendment parameters.
  3. If a function is intended, invoke it with arguments before amending the returned Listing.

Example fix

// before
servers { (env) ->
  new { name = env }
}
// after
servers {
  new { name = "prod" }
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: `someListing { (x) -> ... }` where `someListing` is already a Listing value rather than a function returning a Listing; the parametersDescriptor is non-null while the resolved parent is a Listing.

Common situations: Copy-pasting a function-style amendment onto an existing Listing property; mixing `->` function syntax with object-literal amendment braces; refactoring a function-returned Listing into a plain Listing while keeping parameters.

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/0d3785d1e7d9fca7. Report an issue: GitHub.