{"record":{"id":"1a0dc292deb09139","repo":"apple/pkl","slug":"wronglistingkeytype-1a0dc2","errorCode":"wrongListingKeyType","errorMessage":"Expected key of type `Int`, but got type `{0}`.","messagePattern":"Expected key of type `Int`, but got type `(.+?)`\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java","lineNumber":134,"sourceCode":"  @TruffleBoundary\n  @Idempotent\n  protected final boolean checkIsValidListingAmendment() {\n    if (maxListingMemberIndex != Long.MIN_VALUE) return true;\n\n    var cursor = EconomicMaps.getEntries(members);\n    long maxIndex = -1;\n\n    while (cursor.advance()) {\n      var member = cursor.getValue();\n      if (member.isLocal()) continue;\n\n      var memberName = member.getNameOrNull();\n      if (memberName == null) {\n        var key = cursor.getKey();\n\n        if (!(key instanceof Long)) {\n          CompilerDirectives.transferToInterpreter();\n          throw exceptionBuilder()\n              .evalError(\"wrongListingKeyType\", new ProgramValue(\"\", VmUtils.getClass(key)))\n              .withSourceSection(member.getHeaderSection())\n              .build();\n        }\n\n        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())","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java#L116-L152","documentation":"Listing amendments (`... { ... } amends a Listing` or List entries) must be keyed by integer indices. `checkIsValidListingAmendment` throws this when a member's key in a Listing amendment is not a `Long`, reporting the actual runtime type of the key.","triggerScenarios":"Writing a Listing amendment with a string identifier key instead of an index, e.g. `items { [\"first\"] = ... }` where `items` is a `Listing`; using a Boolean, Float, or other key type where an Int index is expected.","commonSituations":"Confusing `Listing` (positional elements) with `Mapping` (arbitrary keys) — using string keys in a Listing; converting a Mapping-based config to a Listing and forgetting to renumber keys.","solutions":["Replace the key with an integer index (`[0]`, `[1]`, ...) appropriate for the element's position","If arbitrary keys are needed, change the container to a `Mapping` instead of a `Listing`","Remove the mis-keyed member if it was added by mistake"],"exampleFix":"// before (items is a Listing)\nitems { [\"first\"] = 1 }\n// after\nitems { [0] = 1 }\n","handlingStrategy":"type-guard","validationCode":"// Pkl: only use [n] keys in Listing bodies\n// if (key is Int) { items { [key] = v } } else { error(\"Listing keys must be Int indices\") }\n","typeGuard":"function isIntKey(key: Any): Boolean = key is Int\n","tryCatchPattern":null,"preventionTips":["Use `Mapping` when keys are non-numeric","Keep List/Listing bodies strictly positional `[0]`, `[1]`, ..."],"tags":["pkl","listing","key-type","index"],"backgroundTag":"type-mismatch","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"}