{"record":{"id":"e94c18750b72508c","repo":"apple/pkl","slug":"type-mismatch-value-is-not-of-type-listing","errorCode":null,"errorMessage":"type mismatch: value is not of type Listing","messagePattern":"type mismatch: value is not of type Listing","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":1619,"sourceCode":"      return value;\n    }\n\n    @Override\n    protected boolean isParametric() {\n      return true;\n    }\n  }\n\n  public static final class ListingTypeNode extends ListingOrMappingTypeNode {\n    public ListingTypeNode(\n        SourceSection sourceSection, VmLanguage language, TypeNode valueTypeNode) {\n      super(sourceSection, language, null, valueTypeNode);\n    }\n\n    @Override\n    protected Object executeLazily(VirtualFrame frame, Object value) {\n      if (!(value instanceof VmListing vmListing)) {\n        throw typeMismatch(value, BaseModule.getListingClass());\n      }\n      if (vmListing.isValueTypeKnownSubtypeOf(valueTypeNode)) {\n        return vmListing;\n      }\n      return new VmListing(\n          vmListing.getEnclosingFrame(),\n          vmListing,\n          EconomicMaps.emptyMap(),\n          vmListing.getLength(),\n          getValueTypeCastNode(),\n          VmUtils.getReceiver(frame),\n          VmUtils.getOwner(frame));\n    }\n\n    @Override\n    public Object executeEagerly(VirtualFrame frame, Object value) {\n      if (!(value instanceof VmListing vmListing)) {\n        throw typeMismatch(value, BaseModule.getListingClass());","sourceCodeStart":1601,"sourceCodeEnd":1637,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L1601-L1637","documentation":"Thrown by the Listing type-check node's executeLazily when the checked value is not a VmListing. `Listing<T>` is Pkl's heterogeneous, member-based collection type (`new Listing { ... }`); a plain List, Map, or object does not satisfy it, so the node throws typeMismatch naming the `Listing` class before delegating to the value-type check.","triggerScenarios":"A `Listing<T>` constraint (e.g. property `items: Listing<Item>`) receives a non-Listing value: `items = List(...)` (a VmList) instead of `items { ... }` / `new Listing { ... }`.","commonSituations":"Assigning a `List(...)` literal to a Listing-typed property (extremely common Pkl mistake); using `= [ ... ]` bracket syntax where member syntax is required; importing JSON arrays into a Listing-typed property.","solutions":["Use Listing member syntax instead of assignment: `items { new Item { ... }; new Item { ... } }`.","Or build explicitly: `items = new Listing { ... }`.","If the data is genuinely a plain List, change the declared type to `List<T>`.","When converting, iterate the List and add elements into a `new Listing`."],"exampleFix":"// before\nservers: Listing<Server> = List(new Server { host = \"a\" })\n// after\nservers: Listing<Server> {\n  new Server { host = \"a\" }\n}","handlingStrategy":"type-guard","validationCode":"assert(items is Listing<Item>, \"use member syntax: items { ... }, not items = List(...)\")","typeGuard":"items: Listing<Item> = if (items is Listing<Item>) items else new Listing {}","tryCatchPattern":null,"preventionTips":["Use member/amendment syntax (`prop { ... }`) for Listing-typed properties, never `=` with a List literal.","Write empty defaults as `new Listing {}`, not `List()`.","When importing JSON arrays, spread elements into a new Listing."],"tags":["pkl","typecheck","listing","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"}