{"record":{"id":"a17c0349e4e3ba23","repo":"apple/pkl","slug":"type-mismatch-value-is-not-of-type-set","errorCode":null,"errorMessage":"type mismatch: value is not of type Set","messagePattern":"type mismatch: value is not of type Set","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":1488,"sourceCode":"      return consumer.accept(this);\n    }\n\n    @Specialization\n    protected Object eval(VirtualFrame frame, VmSet value) {\n      if (elementTypeNode.isNoopTypeCheck()) return value;\n      for (var elem : value) {\n        // no point doing a lazy check because set members have their hash code computed, which\n        // necessarily deep-forces them.\n        elementTypeNode.executeEagerly(frame, elem);\n      }\n\n      LoopNode.reportLoopCount(this, value.getLength());\n      return value;\n    }\n\n    @Fallback\n    protected Object fallback(Object value) {\n      throw typeMismatch(value, BaseModule.getSetClass());\n    }\n\n    @Override\n    protected boolean isParametric() {\n      return true;\n    }\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","sourceCodeStart":1470,"sourceCodeEnd":1506,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L1470-L1506","documentation":"Thrown from the Set type-check node's @Fallback method: when the specialized set-execution fragments do not match (i.e. the value is not a VmSet), the fallback throws a typeMismatch against the `Set` class. It means a value checked against `Set<T>` (or `c Set` shorthand) is not a Pkl Set.","triggerScenarios":"Executing a `Set<T>` type check with a non-Set value, e.g. `s: Set<Int> = List(1,2,3)` or `s: Set<String> = \"a,b\"`.","commonSituations":"Declaring `Set<T>` but producing a List (very common since List literals are more idiomatic); converting JSON/YAML arrays whose semantics are lists; typo between Set and List in a typealias.","solutions":["Convert the List to a Set: `someList.toSet()`, or use `Set(...)` literal.","Change the declared type from `Set<T>` to `List<T>` if duplicates/order matter.","Remember Pkl `Set` disallows duplicates; ensure the source data is set-like.","Check that conversions of external data preserve Set semantics."],"exampleFix":"// before\ntags: Set<String> = List(\"a\", \"b\")\n// after\ntags: Set<String> = List(\"a\", \"b\").toSet()","handlingStrategy":"validation","validationCode":"assert(s is Set, \"Set<T> requires a Set; convert with .toSet()\")\ns: Set<String> = rawList.toSet()","typeGuard":"function toSetOrNull(v): Set* = if (v is Set) v else null","tryCatchPattern":null,"preventionTips":["Default to List<T> unless uniqueness is actually required.","Call `.toSet()` when adapting List data to Set-typed properties.","Don't interleave `Set<T>` and `List<T>` in a typealias hierarchy."],"tags":["pkl","typecheck","set","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-17T15:17:12.973Z"}