{"record":{"id":"a04718523e859f44","repo":"apple/pkl","slug":"objectamendmentcannothaveparameters","errorCode":"objectAmendmentCannotHaveParameters","errorMessage":"Expected a function that returns an object, but got an object.","messagePattern":"Expected a function that returns an object, but got an object\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorObjectLiteralNode.java","lineNumber":237,"sourceCode":"  @TruffleBoundary\n  protected void fallback(Object parent) {\n    var value = parent;\n    // blame the non-null type (e.g. blame `Duration` instead of `Null` in the case of `Duration?`)\n    if (value instanceof VmNull vmNull) {\n      value = getNullDefaultValue(vmNull);\n    }\n    VmUtils.checkIsInstantiable(\n        value instanceof VmClass vmClass ? vmClass : VmUtils.getClass(value), getParentNode());\n\n    throw exceptionBuilder().unreachableCode().build();\n  }\n\n  @Idempotent\n  protected boolean checkObjectCannotHaveParameters() {\n    if (parametersDescriptor == null) return true;\n\n    CompilerDirectives.transferToInterpreter();\n    throw exceptionBuilder()\n        .evalError(\"objectAmendmentCannotHaveParameters\")\n        .withLocation(getParentNode())\n        .build();\n  }\n\n  @Idempotent\n  protected boolean checkListingCannotHaveParameters() {\n    if (parametersDescriptor == null) return true;\n\n    CompilerDirectives.transferToInterpreter();\n    throw exceptionBuilder()\n        .evalError(\"listingAmendmentCannotHaveParameters\")\n        .withLocation(getParentNode())\n        .build();\n  }\n\n  @Idempotent\n  protected boolean checkMappingCannotHaveParameters() {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorObjectLiteralNode.java#L219-L255","documentation":"When amending an object produced by a function call (e.g. in `new` or an object amendment position), Pkl expects either a plain object or a function returning an object. An amendment targeting a Dynamic object that declares parameters is rejected: parameterized object literals cannot be amended this way.","triggerScenarios":"Applying an amendment (`foo { ... }`) to an expression that is a Dynamic object (not a function returning one), where the amendment carries a parameters list (`(x) -> ...`), via `checkObjectCannotHaveParameters` in GeneratorObjectLiteralNode.","commonSituations":"Confusing `new Foo { ... }` / `Foo { ... }` amendment syntax with function-call syntax; adding `(param) ->` to an amendment of a plain object instead of a function; migrating code where the target changed from a function to an object.","solutions":["Remove the parameter list from the amendment; amend the object directly (`obj { ... }`).","If parameters are intended, call the function: `obj(params) { ... }` so the target is a function returning an object.","Verify the target expression's type — a Dynamic object cannot accept amendment parameters."],"exampleFix":"// before\nbase { (x) ->\n  y = x\n}\n// after\nbase {\n  y = 42\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reserve `(p) -> { ... }` parameter syntax for functions; use plain `{ ... }` for object amendments.","Check the target's type before amending: a Dynamic object takes no parameters.","Call functions with parentheses instead of amendment parameter syntax."],"tags":["pkl","object-amendment","parameters","syntax"],"backgroundTag":"invalid-argument","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"}