{"record":{"id":"b178bf70fb2523ac","repo":"apple/pkl","slug":"listingamendmentcannothaveparameters-b178bf","errorCode":"listingAmendmentCannotHaveParameters","errorMessage":"Expected a function that returns a `Listing`, but got a `Listing`.","messagePattern":"Expected a function that returns a `Listing`, but got a `Listing`\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java","lineNumber":158,"sourceCode":"        long index = (long) key;\n        if (index < 0) {\n          // defer handling of negative index to checkMaxListingMemberIndex() (gives more uniform\n          // error messages)\n          maxIndex = Long.MAX_VALUE;\n          break;\n        } else if (index > maxIndex) {\n          maxIndex = index;\n        }\n      } else if (memberName != Identifier.DEFAULT) {\n        throw exceptionBuilder()\n            .evalError(\"objectCannotHaveProperty\", BaseModule.getListingClass())\n            .withSourceSection(member.getHeaderSection())\n            .build();\n      }\n    }\n\n    if (parametersDescriptor != null) {\n      throw exceptionBuilder()\n          .evalError(\"listingAmendmentCannotHaveParameters\")\n          .withSourceSection(getParentNode().getSourceSection())\n          .build();\n    }\n\n    maxListingMemberIndex = maxIndex;\n    return true;\n  }\n\n  @SuppressWarnings(\"SameReturnValue\")\n  @TruffleBoundary\n  @Idempotent\n  protected final boolean checkIsValidMappingAmendment() {\n    if (checkedIsValidMappingAmendment) return true;\n\n    for (var member : EconomicMaps.getValues(members)) {\n      if (member.isLocal()) continue;\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java#L140-L176","documentation":"A Listing amendment must be a plain object literal — it cannot introduce function parameters, because the amended value is a `Listing` produced by an expression, not a parameterized object constructor. `checkIsValidListingAmendment` throws this when `parametersDescriptor` is non-null, i.e. the amendment literal declares a parameter list.","triggerScenarios":"Writing `items { (x) { ... } }`-style or `amends (a) -> ...` parameterized amendment targeting a Listing; applying a function-shaped object literal to a Listing parent.","commonSituations":"Copy-pasting a parameterized `amends` pattern from a class-typed object onto a Listing; misunderstanding that only class-amending literals support parameters.","solutions":["Remove the parameter list from the Listing amendment and inline the values","If parameterization is required, amend a class whose property returns the Listing, parameterizing at that level instead","Compute the elements in a separate expression/function and assign the result rather than parameterizing the amendment"],"exampleFix":"// before\nitems { (x) { [0] = x } }\n// after\nitems { [0] = 42 }\n","handlingStrategy":"validation","validationCode":"// Listing amendments take no parameter list: write items { [0] = v } not items { (x) { ... } }\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only class-amending literals support parameter lists","Parameterize with functions that return Listings instead"],"tags":["pkl","listing","amends","parameters"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}