{"record":{"id":"1149ef15c342ce6b","repo":"apple/pkl","slug":"wronglistingkeytype","errorCode":"wrongListingKeyType","errorMessage":"wrongListingKeyType ${type}","messagePattern":"wrongListingKeyType (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorEntryNode.java","lineNumber":95,"sourceCode":"  @Fallback\n  @SuppressWarnings(\"unused\")\n  void fallback(Object parent, ObjectData data) {\n    CompilerDirectives.transferToInterpreter();\n    throw exceptionBuilder().evalError(\"objectCannotHaveEntry\", parent).build();\n  }\n\n  private void addRegularEntry(VirtualFrame frame, ObjectData data) {\n    var key = keyNode.executeGeneric(frame);\n    data.addMember(frame, key, member, this);\n  }\n\n  private void addListingEntry(VirtualFrame frame, ObjectData data, int parentLength) {\n    long index;\n    try {\n      index = keyNode.executeInt(frame);\n    } catch (UnexpectedResultException e) {\n      CompilerDirectives.transferToInterpreter();\n      throw exceptionBuilder()\n          .evalError(\"wrongListingKeyType\", new ProgramValue(\"\", VmUtils.getClass(e.getResult())))\n          .withLocation(keyNode)\n          .build();\n    }\n\n    // use same error messages as in checkIsValidListingAmendment and checkMaxListingMemberIndex\n    if (index < 0 || index >= parentLength) {\n      CompilerDirectives.transferToInterpreter();\n      throw exceptionBuilder()\n          .evalError(\"elementIndexOutOfRange\", index, 0, parentLength - 1)\n          .withLocation(keyNode)\n          .build();\n    }\n\n    data.addMember(frame, index, member, this);\n  }\n}\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorEntryNode.java#L77-L113","documentation":"Thrown when a `Listing` is amended with an entry whose key is not a non-negative integer index. Listing keys must be integers (the next element index); if the key expression evaluates to any other type (String, Float, etc.) this error reports the key's actual type.","triggerScenarios":"Amending a Listing with `[\"key\"] = value` or `[1.5] = value` — the key node's `executeInt` throws UnexpectedResultException and the actual key type is reported.","commonSituations":"Copy-pasting Mapping entry syntax into a Listing amendment, using string keys expecting map-like behavior, JSON with mixed arrays/objects converted incorrectly.","solutions":["Use integer indices for Listing keys (or the empty-key shorthand `[*]` / `_` for the next index)","Switch the parent to a `Mapping` if string keys are required","Fix the key expression to evaluate to an `Int`","Check the amendment site — the error location points at the key node"],"exampleFix":"// before\nlist = new Listing { [\"first\"] = 1 }\n// after\nlist = new Listing { [0] = 1 }","handlingStrategy":"validation","validationCode":"function isValidListingKey(k) { return Number.isInteger(k) && k >= 0 }","typeGuard":"function isIntKey(k) { return typeof k === 'number' && Number.isInteger(k) }","tryCatchPattern":null,"preventionTips":["Listing keys must be non-negative Integers","Use Mapping when string keys are needed","Use the next-index shorthand for appending"],"tags":["pkl","listing","key-type"],"backgroundTag":"invalid-argument-format","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"}