{"record":{"id":"6a5fecd1d4b9aaa6","repo":"apple/pkl","slug":"type-mismatch-value-is-not-of-type-list","errorCode":null,"errorMessage":"type mismatch: value is not of type List","messagePattern":"type mismatch: value is not of type List","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":1371,"sourceCode":"\n    public TypeNode getElementTypeNode() {\n      return elementTypeNode;\n    }\n\n    @Override\n    public VmList getTypeArgumentMirrors() {\n      return VmList.of(elementTypeNode.getMirror());\n    }\n\n    @Override\n    protected PType doExport() {\n      return new PType.Class(BaseModule.getListClass().export(), elementTypeNode.doExport());\n    }\n\n    @Override\n    public Object executeEagerly(VirtualFrame frame, Object value) {\n      if (!(value instanceof VmList vmList)) {\n        throw typeMismatch(value, BaseModule.getListClass());\n      }\n      if (elementTypeNode.isNoopTypeCheck()) return vmList;\n\n      for (var elem : vmList) {\n        elementTypeNode.executeEagerly(frame, elem);\n      }\n\n      LoopNode.reportLoopCount(this, vmList.getLength());\n      return value;\n    }\n\n    @SuppressWarnings(\"DuplicatedCode\")\n    @Override\n    @ExplodeLoop\n    protected Object executeLazily(VirtualFrame frame, Object value) {\n      if (!(value instanceof VmList vmList)) {\n        throw typeMismatch(value, BaseModule.getListClass());\n      }","sourceCodeStart":1353,"sourceCodeEnd":1389,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L1353-L1389","documentation":"Thrown by the List type-check node's executeEagerly when a value checked against a `List<T>` constraint is not a VmList. The type node first verifies the outer value is a List before running the per-element type check, so any non-List value (String, Set, Map, null, etc.) immediately fails. This is the eager (value fully evaluated) code path of List type checking.","triggerScenarios":"Evaluating a property/typealias/assert declared `List<T>` where the bound value is not a Pkl List instance, e.g. `xs: List<Int> = Set(1,2)` or `xs: List<Int> = 5`.","commonSituations":"Confusing List with Set or Listing; passing a string where a list of strings was intended; returning a Map from an expression typed as List; misconfigured external property (e.g. CLI/env-provided value substituted as scalar).","solutions":["Wrap or convert the value into a List: `List(...)` or `.toList()` where available.","If the value is a Set/Listing, change the declared type to the matching collection type.","Check each element too: once the outer type passes, elements must satisfy `T`.","Reproduce in the REPL with `\"...\": List<Int>` style assertion to see which value fails."],"exampleFix":"// before\nports: List<Int> = Set(8080, 9090)\n// after\nports: List<Int> = List(8080, 9090)","handlingStrategy":"type-guard","validationCode":"assert(xs is List, \"expected a List, got ${xs.getClass().simpleName}\")","typeGuard":"xs: List<Int> = if (xs is List) xs else throw(\"not a List\") // or host: value is PklList","tryCatchPattern":null,"preventionTips":["Use `List(...)` literals, not Set/Map, for List-typed properties.","Keep typealiases accurate (List vs Set vs Listing).","Validate external/CLI-provided values with `is List` before use."],"tags":["pkl","typecheck","list","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"}