{"record":{"id":"21004ebba3b8ceac","repo":"apple/pkl","slug":"missingmapvalue","errorCode":"missingMapValue","errorMessage":"missingMapValue","messagePattern":"missingMapValue","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":1401,"sourceCode":"    if (elementNodes.first.length == 0) {\n      return new ConstantValueNode(VmSet.EMPTY);\n    }\n\n    return elementNodes.second\n        ? new ConstantValueNode(\n            createSourceSection(expr), VmSet.createFromConstantNodes(elementNodes.first))\n        : new SetLiteralNode(createSourceSection(expr), elementNodes.first);\n  }\n\n  private ExpressionNode doVisitMapLiteral(Expr expr, ArgumentList argList) {\n    var keyAndValueNodes = createCollectionArgumentNodes(argList);\n\n    if (keyAndValueNodes.first.length == 0) {\n      return new ConstantValueNode(VmMap.EMPTY);\n    }\n\n    if (keyAndValueNodes.first.length % 2 != 0) {\n      throw exceptionBuilder()\n          .evalError(\"missingMapValue\")\n          .withSourceSection(createSourceSection(argList.span().stopSpan()))\n          .build();\n    }\n\n    return keyAndValueNodes.second\n        ? new ConstantValueNode(\n            createSourceSection(expr), VmMap.createFromConstantNodes(keyAndValueNodes.first))\n        : new MapLiteralNode(createSourceSection(expr), keyAndValueNodes.first);\n  }\n\n  private ExpressionNode doVisitBytesLiteral(Expr expr, ArgumentList argList) {\n    var elementNodes = createCollectionArgumentBytesNodes(argList);\n\n    if (elementNodes.first.length == 0) {\n      return new ConstantValueNode(VmBytes.EMPTY);\n    }\n    return elementNodes.second","sourceCodeStart":1383,"sourceCodeEnd":1419,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L1383-L1419","documentation":"Map constructors in Pkl take alternating key/value arguments. When the builder collects the key-value argument pairs and the count is odd, there is a key with no corresponding value, so it throws missingMapValue at the trailing span.","triggerScenarios":"Writing `Map(1, \"one\", 2)` — an odd number of arguments to a Map(...) constructor, leaving the last key without a value.","commonSituations":"Accidentally deleting a value while editing, or misusing the positional Map constructor expecting key-value pair syntax instead of flat alternation.","solutions":["Supply the missing value so arguments alternate key, value, key, value.","Remove the dangling key if it was unintended.","Prefer `new Map { [\"k\"] = v ... }` entry syntax to avoid positional alternation mistakes."],"exampleFix":"// before\nm = Map(1, \"one\", 2)\n// after\nm = Map(1, \"one\", 2, \"two\")","handlingStrategy":"validation","validationCode":"// Validate Map(...) constructor argument count is even:\nfunction validMapArgs(args) {\n  return Array.isArray(args) && args.length % 2 === 0;\n}","typeGuard":"const hasEvenEntries = (args: unknown[]): boolean => args.length % 2 === 0;","tryCatchPattern":null,"preventionTips":["Prefer `new Map { [k] = v }` entry syntax over the positional Map(...) constructor.","When editing flat key-value lists, check pair alignment afterwards."],"tags":["pkl","map","arguments"],"backgroundTag":"missing-required-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"}