{"record":{"id":"b666f61d2dea5bec","repo":"apple/pkl","slug":"duplicatedefinition-b666f6","errorCode":"duplicateDefinition","errorMessage":"Duplicate definition of member `{0}`.","messagePattern":"Duplicate definition of member `(.+?)`\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java","lineNumber":255,"sourceCode":"            .evalError(\"wrongListingKeyType\", new ProgramValue(\"\", VmUtils.getClass(e.getResult())))\n            .withSourceSection(keyNodes[i].getSourceSection())\n            .build();\n      }\n\n      var value = values[i];\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            .withSourceSection(value.getHeaderSection())\n            .build();\n      }\n\n      if (EconomicMaps.put(result, index, value) != null) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder()\n            .evalError(\"duplicateDefinition\", new ProgramValue(\"\", index))\n            .withSourceSection(value.getHeaderSection())\n            .build();\n      }\n    }\n  }\n\n  @TruffleBoundary\n  protected @Nullable ObjectMember findFirstNonProperty(\n      UnmodifiableEconomicMap<Object, ObjectMember> members) {\n    var cursor = EconomicMaps.getEntries(members);\n    while (cursor.advance()) {\n      var member = cursor.getValue();\n      if (member.getNameOrNull() == null) return member;\n    }\n    return null;\n  }\n","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java#L237-L273","documentation":"Pkl throws `duplicateDefinition` when two members resolve to the same key/index within one object literal. In addListEntries, `EconomicMaps.put(result, index, value)` returning non-null means two element expressions amended the same element index, so Pkl refuses the ambiguous definition.","triggerScenarios":"Two `[n]` element amendments with the same index inside one amending object literal; spread/`...` plus an explicit `[n]` that collides with an index already produced by the spread.","commonSituations":"Merging listing amendments where a spread already covers index 0 and an explicit `[0]` is also written; generated or templated code emitting the same index twice.","solutions":["Remove one of the conflicting `[n]` amendments for that index.","Merge the two element bodies into a single `[n]` amendment.","If using a spread (`...`), verify which indices it already provides before adding explicit amendments."],"exampleFix":"// before\nobj {\n  elements {\n    [0] { name = \"a\" }\n    [0] { name = \"b\" } // duplicate\n  }\n}\n// after\nobj {\n  elements {\n    [0] { name = \"b\" }\n  }\n}","handlingStrategy":"validation","validationCode":"// Pkl: track indices you amend\nindices = Set(0, 2)\nassert(indices.length == 2, \"duplicate element index in amendment\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a single amendment per element index in each literal.","When combining spreads with explicit indices, enumerate spread indices first.","Review generated/templated amendments for repeated indices."],"tags":["pkl","duplicate-key","listing","amendment"],"backgroundTag":"duplicate-definition","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"}