apple/pkl · error · VmTypeMismatchException
type mismatch: value is not of type Listing
Error message
type mismatch: value is not of type Listing
What it means
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.
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`.
Example fix
// before
servers: Listing<Server> = List(new Server { host = "a" })
// after
servers: Listing<Server> {
new Server { host = "a" }
} Defensive patterns
Strategy: type-guard
Validate before calling
assert(items is Listing<Item>, "use member syntax: items { ... }, not items = List(...)") Type guard
items: Listing<Item> = if (items is Listing<Item>) items else new Listing {} Prevention
- 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.
When it happens
Trigger: A `Listing<T>` constraint (e.g. property `items: Listing<Item>`) receives a non-Listing value: `items = List(...)` (a VmList) instead of `items { ... }` / `new Listing { ... }`.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- type mismatch: value does not conform to declared type…
- type mismatch: value is not an instance of expected…
- type mismatch: value is not of type Collection
- type mismatch: value is not of type Dynamic
- type mismatch: value is not of type List
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/e94c18750b72508c.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java:1619
return value;
}
@Override
protected boolean isParametric() {
return true;
}
}
public static final class ListingTypeNode extends ListingOrMappingTypeNode {
public ListingTypeNode(
SourceSection sourceSection, VmLanguage language, TypeNode valueTypeNode) {
super(sourceSection, language, null, valueTypeNode);
}
@Override
protected Object executeLazily(VirtualFrame frame, Object value) {
if (!(value instanceof VmListing vmListing)) {
throw typeMismatch(value, BaseModule.getListingClass());
}
if (vmListing.isValueTypeKnownSubtypeOf(valueTypeNode)) {
return vmListing;
}
return new VmListing(
vmListing.getEnclosingFrame(),
vmListing,
EconomicMaps.emptyMap(),
vmListing.getLength(),
getValueTypeCastNode(),
VmUtils.getReceiver(frame),
VmUtils.getOwner(frame));
}
@Override
public Object executeEagerly(VirtualFrame frame, Object value) {
if (!(value instanceof VmListing vmListing)) {
throw typeMismatch(value, BaseModule.getListingClass());View on GitHub (pinned to f3efcbfc9b)