{"record":{"id":"451957908486979c","repo":"apple/pkl","slug":"type-mismatch-value-is-not-of-type-pair","errorCode":null,"errorMessage":"type mismatch: value is not of type Pair","messagePattern":"type mismatch: value is not of type Pair","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":2327,"sourceCode":"\n    public PairTypeNode(\n        SourceSection sourceSection, TypeNode firstTypeNode, TypeNode secondTypeNode) {\n      super(sourceSection);\n      this.firstTypeNode = firstTypeNode;\n      this.secondTypeNode = secondTypeNode;\n    }\n\n    @Override\n    protected Object executeLazily(VirtualFrame frame, Object value) {\n      if (value instanceof VmPair vmPair) {\n        var first = firstTypeNode.executeLazily(frame, vmPair.getFirst());\n        var second = secondTypeNode.executeLazily(frame, vmPair.getSecond());\n        if (first == vmPair.getFirst() && second == vmPair.getSecond()) {\n          return vmPair;\n        }\n        return new VmPair(first, second);\n      }\n      throw typeMismatch(value, BaseModule.getPairClass());\n    }\n\n    @Override\n    public Object executeEagerly(VirtualFrame frame, Object value) {\n      if (value instanceof VmPair vmPair) {\n        firstTypeNode.executeEagerly(frame, vmPair.getFirst());\n        secondTypeNode.executeEagerly(frame, vmPair.getSecond());\n        return value;\n      }\n      throw typeMismatch(value, BaseModule.getPairClass());\n    }\n\n    @Override\n    public VmClass getVmClass() {\n      return BaseModule.getPairClass();\n    }\n\n    @Override","sourceCodeStart":2309,"sourceCodeEnd":2345,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L2309-L2345","documentation":"Thrown by PairTypeNode.executeLazily when a lazily-checked value is not a VmPair. The node first typechecks both components of a Pair against its element types; a non-Pair value falls through to this error.","triggerScenarios":"A value annotated `Pair<X, Y>` receives something that is not a pkl Pair (e.g. a List, Listing, Int, or null) during lazy (speculative/slow-path) evaluation.","commonSituations":"Using stdlib Pair types in annotations and assigning a two-element Listing or List literal; passing tuples from other languages; building config where a Pair is expected but an array-like value was written.","solutions":["Construct a real Pair with `Pair(first, second)` instead of a list/tuple-like value.","Verify the value is not null or a differently-shaped collection.","If the annotation should accept a list, change the type to `Listing`/`List` accordingly.","Trace the failing property's annotation and align value construction with `Pair(a, b)`."],"exampleFix":"// before\np: Pair<Int, Int> = List(1, 2)\n\n// after\np: Pair<Int, Int> = Pair(1, 2)","handlingStrategy":"validation","validationCode":"if (value is Pair) { /* ok */ } else { throw \"expected Pair\" }","typeGuard":"function isPair(v: Any): Boolean = v is Pair","tryCatchPattern":null,"preventionTips":["Always build Pairs with Pair(a, b), not List(a, b).","Don't interchange List/Listing and Pair types in annotations.","Guard against nulls reaching Pair-typed properties."],"tags":["pkl","type-mismatch","pair"],"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"}