{"record":{"id":"8337f54a872ca434","repo":"apple/pkl","slug":"wrongfunctionamendmentparametercount","errorCode":"wrongFunctionAmendmentParameterCount","errorMessage":"Expected a function with {0} parameters, but got {1}.","messagePattern":"Expected a function with (.+?) parameters, but got (.+?)\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/literal/ObjectLiteralNode.java","lineNumber":89,"sourceCode":"  }\n\n  @Idempotent\n  protected static boolean isTypedObjectClass(VmClass clazz) {\n    if (clazz.isListingClass()\n        || clazz.isMappingClass()\n        || clazz.isDynamicClass()\n        || clazz.isFunctionClass()\n        || clazz.isFunctionNClass()) {\n      return false;\n    }\n    return BaseModule.getTypedClass().isSuperclassOf(clazz);\n  }\n\n  protected final boolean checkIsValidFunctionAmendment(VmFunction parent) {\n    var length = parameterTypes.length;\n    if (length > 0 && length != parent.getParameterCount()) {\n      CompilerDirectives.transferToInterpreter();\n      throw exceptionBuilder()\n          .evalError(\"wrongFunctionAmendmentParameterCount\", length, parent.getParameterCount())\n          .withSourceSection(getParentNode().getSourceSection())\n          .build();\n    }\n    return true;\n  }\n\n  @Idempotent\n  protected final boolean checkIsValidFunctionAmendment(Object parent) {\n    return checkIsValidFunctionAmendment((VmFunction) parent);\n  }\n\n  @Idempotent\n  protected final boolean isFunction(Object value) {\n    return value instanceof VmFunction;\n  }\n\n  protected final Object getNullDefaultValue(VmNull parent) {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/ObjectLiteralNode.java#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Count the parameters on the amended parent function and give the amendment's parameter list exactly that many parameters","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)","Update the parent function signature consistently and fix all amendment sites, or bump versions so amendments are regenerated"],"exampleFix":"// before\nfoo = (x) -> new { ... }\nbar { amends foo } // or (a, b) { amends foo }\n// after\nbar (x) { amends foo } // parameter count matches parent\n","handlingStrategy":"validation","validationCode":"// Pkl: before amending, assert parameter counts line up (mentally or via test)\n// function foo(x) { ... }\n// amendment must be: bar (x) { amends foo }\n// Test in Pkl: validated automatically at eval; keep base and amendments in one module to catch drift.\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep `amends` literals adjacent to the function they amend","Grep for `amends` of a function whenever its signature changes","Prefer amending classes (property count is checked by name) over parameterized functions"],"tags":["pkl","amends","function-signature","parameters"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}