apple/pkl · error · VmException

tooManyFunctionParameters

tooManyFunctionParameters

Error message

tooManyFunctionParameters

What it means

Pkl function types and lambdas support at most 5 parameters. When the builder constructs a function node whose parameter list exceeds 5, it throws tooManyFunctionParameters — enforced because of frame-descriptor and call-convention limits in the runtime.

Source

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

              sourceSection,
              scope.getQualifiedName(),
              t,
              bodyExpr,
              b == null ? -1 : b.slot(),
              bindingExpr);
        });
  }

  @Override
  public ExpressionNode visitFunctionLiteralExpr(FunctionLiteralExpr expr) {
    var sourceSection = createSourceSection(expr);
    var params = expr.getParameterList();
    var descriptorBuilderAndBindings = createFrameDescriptorBuilderAndSlotVariables(params);
    var paramCount = params.getParameters().size();
    var descriptorBuilder = descriptorBuilderAndBindings.first;
    var bindings = descriptorBuilderAndBindings.second;
    if (paramCount > 5) {
      throw exceptionBuilder()
          .evalError("tooManyFunctionParameters")
          .withSourceSection(sourceSection)
          .build();
    }

    var isCustomThisScope = symbolTable.getCurrentScope().isCustomThisScope();

    return symbolTable.enterLambda(
        bindings,
        descriptorBuilder,
        scope -> {
          var exprNode = visitExpr(expr.getExpr());
          var functionNode =
              new UnresolvedFunctionNode(
                  language,
                  scope.buildFrameDescriptor(),
                  new Lambda(sourceSection, scope.getQualifiedName()),
                  paramCount,

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Reduce arity to 5 or fewer by grouping related parameters into an object or listing.
  2. Accept a single config object (`(ctx) -> ...`) and read fields from it.
  3. Split the function into smaller composed functions.

Example fix

// before
(a, b, c, d, e, f) -> a + b + c + d + e + f
// after
(ctx) -> ctx.a + ctx.b + ctx.c + ctx.d + ctx.e + ctx.f
Defensive patterns

Strategy: validation

Validate before calling

// Reject high-arity lambdas at generation time:
if (params.length > 5) throw new Error('Pkl lambdas support at most 5 parameters');

Prevention

When it happens

Trigger: Declaring a function or lambda with 6+ parameters, e.g. `(a, b, c, d, e, f) -> ...`, or a typed function type `function6` usage.

Common situations: Porting code from languages with high-arity lambdas, or defining a callback with many config knobs as separate parameters.

Related errors


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