apple/pkl · error
wrongArgumentCount
wrongArgumentCount
Error message
wrongArgumentCount
What it means
Pkl throws wrongArgumentCount when a function is invoked with a number of arguments that does not match its declared parameter count. FunctionNode.executeImpl compares the frame's argument count (minus implicit receiver parameters) against totalParamCount and raises the error listing expected vs actual counts. Pkl functions have fixed arity — no overloads or default arguments bridge a mismatch.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/member/FunctionNode.java:113
var sb = new StringBuilder(member.getName().toString());
sb.append('(');
for (var i = 0; i < Math.min(getFrameDescriptor().getNumberOfSlots(), paramCount); i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(getFrameDescriptor().getSlotName(i));
}
sb.append(')');
return sb.toString();
}
@Override
@ExplodeLoop
protected Object executeImpl(VirtualFrame frame) {
var totalArgCount = frame.getArguments().length;
if (totalArgCount != totalParamCount) {
CompilerDirectives.transferToInterpreter();
throw wrongArgumentCount(totalArgCount - IMPLICIT_PARAM_COUNT);
}
for (var i = 0; i < parameterTypeNodes.length; i++) {
var argument = frame.getArguments()[IMPLICIT_PARAM_COUNT + i];
parameterTypeNodes[i].executeAndSet(frame, argument);
}
var result = bodyNode.executeGeneric(frame);
if (checkedReturnTypeNode != null) {
return checkedReturnTypeNode.execute(frame, result);
}
return result;
}
public VmMap getParameterMirrors() {
var builder = VmMap.builder();View on GitHub (pinned to f3efcbfc9b)
Solutions
- Read expected vs actual counts from the error message and add or remove arguments at the call site to match.
- Check the function's current signature in the imported module/package — a version change may have altered arity.
- If arguments are optional by design, provide the new required value or use the library's default-preserving overload.
- Pin the package version or update call sites when upgrading dependencies.
Example fix
// before
join("-", parts, " ") // extra argument
// after
join("-", parts) Defensive patterns
Strategy: type-guard
Validate before calling
// Check arity against the imported module's declaration before calling: // import "lib.pkl" // lib.join has (sep, values) -> call with exactly 2 arguments.
Type guard
// Prefer typed function references in Pkl: // f: (String, List<String>) -> String = lib.join // mis-arity calls then fail type checking instead of at runtime.
Prevention
- Use typed function references so arity mismatches surface at type-check time.
- Read the function signature before calling, especially for package functions.
- Pin package versions; update call sites when signatures change on upgrade.
- Let pkl-lsp autocomplete insert the correct argument list.
When it happens
Trigger: Calling a Pkl function with too few or too many arguments; passing a function reference with a different signature where a fixed-arity function is expected; library function signature changed between versions while caller was not updated; miscounting implicit receiver/owner parameters in generated calls.
Common situations: Upgrading a package whose function gained or lost a parameter; hand-writing calls to generated or standard-library functions; invoking a two-parameter function inside a `let` or default-value expression with leftover arguments from a refactor.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- wrongFunctionArgumentCount
- tooManyFunctionParameters
- wrongTypeArgumentCount
- Node `%s` of type `%s` does not have a property named `%s`.
- JavaType token must be parameterized.
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/48a27e99816b1896.
Report an issue: GitHub.