{"record":{"id":"06e896cb8ba52ac8","repo":"apple/pkl","slug":"type-mismatch-value-is-not-of-type-map","errorCode":null,"errorMessage":"type mismatch: value is not of type Map","messagePattern":"type mismatch: value is not of type Map","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":1512,"sourceCode":"    }\n  }\n\n  public static final class MapTypeNode extends ObjectSlotTypeNode {\n    @Child private TypeNode keyTypeNode;\n    @Child private TypeNode valueTypeNode;\n\n    public MapTypeNode(SourceSection sourceSection, TypeNode keyTypeNode, TypeNode valueTypeNode) {\n      super(sourceSection);\n      this.keyTypeNode = keyTypeNode;\n      this.valueTypeNode = valueTypeNode;\n    }\n\n    @Override\n    protected Object executeLazily(VirtualFrame frame, Object value) {\n      if (value instanceof VmMap vmMap) {\n        return eval(frame, vmMap);\n      }\n      throw typeMismatch(value, BaseModule.getMapClass());\n    }\n\n    @Override\n    public Object executeEagerly(VirtualFrame frame, Object value) {\n      if (value instanceof VmMap vmMap) {\n        return evalEager(frame, vmMap);\n      }\n      throw typeMismatch(value, BaseModule.getMapClass());\n    }\n\n    @Override\n    public Object createDefaultValue(\n        VirtualFrame frame,\n        VmLanguage language,\n        SourceSection headerSection,\n        String qualifiedName) {\n\n      return VmMap.EMPTY;","sourceCodeStart":1494,"sourceCodeEnd":1530,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L1494-L1530","documentation":"Thrown by the Map type-check node's executeLazily when a value checked against `Map<K,V>` is not a VmMap. Only VmMap instances proceed to the lazy key/value checks; anything else (List, Listing, Set, String, object, null) throws the typeMismatch error naming the `Map` type.","triggerScenarios":"A lazily-executed `Map<K,V>` constraint receives a non-Map value, e.g. `m: Map<String, Int> = List(1,2)` or assigning a Listing/object to a Map-typed property.","commonSituations":"Confusing `Map` with `Mapping` (objects with member syntax) or `List`/`Listing`; parsing external YAML/JSON where a key/value block became a list; using `Map(...).entries` result (a List) where the Map itself was expected.","solutions":["Produce an actual Map: `Map(\"k\", 1, \"k2\", 2)` or keep the Map instead of extracting entries.","If the value is an object, declare the property as `Mapping` instead of `Map`.","If you called `.entries`/`.keys`/`.values`, use the original map or change the declared type to List.","Convert pairs: `ListPair(...).toMap()` style APIs where available."],"exampleFix":"// before\ncounts: Map<String, Int> = countsMap.entries // List of pairs\n// after\ncounts: Map<String, Int> = countsMap","handlingStrategy":"type-guard","validationCode":"assert(m is Map<String, Int>, \"expected Map<String, Int>\")","typeGuard":"function asMap(v): Map<String, Int> = if (v is Map<String, Int>) v else Map()","tryCatchPattern":null,"preventionTips":["Don't assign `map.entries`/`map.keys`/`map.values` (Lists) to Map-typed properties.","Distinguish Map (literal key/value pairs) from Mapping (object).","When ingesting YAML/JSON, build Maps explicitly."],"tags":["pkl","typecheck","map","type-mismatch"],"backgroundTag":"type-mismatch","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"}