{"record":{"id":"9b7e7e853652c52e","repo":"apple/pkl","slug":"cannotaddelementwithentrysyntax","errorCode":"cannotAddElementWithEntrySyntax","errorMessage":"Cannot use entry syntax to add an element.","messagePattern":"Cannot use entry syntax to add an element\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/literal/EntriesLiteralNode.java","lineNumber":175,"sourceCode":"      VirtualFrame frame, @SuppressWarnings(\"unused\") VmClass parent) {\n    return new VmMapping(\n        frame.materialize(), BaseModule.getMappingClass().getPrototype(), createMapMembers(frame));\n  }\n\n  @Specialization(guards = \"parent == getDynamicClass()\")\n  protected VmDynamic evalDynamicClass(\n      VirtualFrame frame, @SuppressWarnings(\"unused\") VmClass parent) {\n    return new VmDynamic(\n        frame.materialize(),\n        BaseModule.getDynamicClass().getPrototype(),\n        createMapMembers(frame),\n        0);\n  }\n\n  @Specialization(guards = {\"parent == getListingClass()\", \"checkIsValidListingAmendment()\"})\n  protected void evalListingClass(@SuppressWarnings(\"unused\") VmClass parent) {\n    CompilerDirectives.transferToInterpreter();\n    throw exceptionBuilder()\n        .evalError(\"cannotAddElementWithEntrySyntax\")\n        .withSourceSection(keyNodes[0].getSourceSection())\n        .build();\n  }\n\n  @Fallback\n  @TruffleBoundary\n  protected Object 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    return elementsEntriesFallback(value, values[0], false);\n  }\n\n  @ExplodeLoop\n  protected EconomicMap<Object, ObjectMember> createMapMembers(VirtualFrame frame) {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/EntriesLiteralNode.java#L157-L193","documentation":"EntriesLiteralNode error 'Cannot use entry syntax to add an element.': entry syntax `[key] = value` is only valid for map-like objects (object/mapping/dynamic); applying it to a Listing parent (which holds plain elements, not keyed entries) is rejected. The input at fault is an entries-literal member added to a Listing.","triggerScenarios":"`Listing { [\"key\"] = value }` or `[k] = v` inside an object literal amending the Listing class, with the first key node's section reported.","commonSituations":"Copy-pasting a Mapping/Dynamic literal into a Listing, or adding named entries to a list-shaped config.","solutions":["Use plain element syntax (`new { ... }` or positional entries) for Listings.","Change the parent object to a Dynamic or Mapping if keyed entries are intended."],"exampleFix":"// before\nnew Listing<String> {\n  [\"a\"] = \"x\"\n}\n// after\nnew Mapping<String> {\n  [\"a\"] = \"x\"\n}","handlingStrategy":"validation","validationCode":"// Listing bodies must use element syntax only\n// wrong: [\"k\"] = v  |  right: v","typeGuard":"function isEntryContainer(t) { return t is Dynamic || t is Mapping; }","tryCatchPattern":null,"preventionTips":["Use element syntax inside Listing; entry syntax inside Mapping/Dynamic.","When converting a literal between container types, rewrite `[k] = v` lines.","Check amends target: if it is Listing, remove entry syntax."],"tags":["pkl","listing","entry-syntax"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}