apple/pkl · error · VmTypeMismatchException

type mismatch: value is not of type Function

Error message

type mismatch: value is not of type Function

What it means

TypeNode.FunctionTypeNode type check: a value checked against a Function type (`(X) -> Y`) is not a VmFunction, so the @Fallback throws a type-mismatch error. The input at fault is any non-function value used where a function type annotation is expected.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java:2076

    public final VmList getTypeArgumentMirrors() {
      return VmList.of(typeArgumentNode.getMirror());
    }

    @Override
    protected final PType doExport() {
      return new PType.Class(BaseModule.getFunctionClass().export(), typeArgumentNode.doExport());
    }

    @Specialization
    protected Object eval(VmFunction value) {
      /* do nothing */
      return value;
    }

    @Fallback
    protected void fallback(Object value) {
      throw typeMismatch(value, BaseModule.getFunctionClass());
    }

    @Override
    public boolean doIsEquivalentTo(TypeNode other) {
      if (!(other instanceof FunctionClassTypeNode functionClassTypeNode)) {
        return false;
      }
      return typeArgumentNode.isEquivalentTo(functionClassTypeNode.typeArgumentNode);
    }

    @Override
    protected boolean acceptTypeNode(boolean visitTypeArguments, TypeNodeConsumer consumer) {
      return consumer.accept(this);
    }

    @Override
    protected boolean isParametric() {
      return true;

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Supply an actual function value (e.g. `(n) -> n * 2`) where the function type is required.
  2. Correct the type annotation if the property is not meant to be a function type.

Example fix

// before
transform: Function = value * 2

// after
transform: Function = (v) -> v * 2
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is Function) { /* ok */ } else { throw "expected a function" }

Type guard

function isFunction(v: Any): Boolean = v is Function

Try / catch

// catch VmTypeMismatchException.Simple around evaluation and report the failing property
try { evalTypeCheck() } catch (e: VmTypeMismatchException) { report(e.sourceSection, e) }

Prevention

When it happens

Trigger: A type annotation `x: Function` (or a signature returning `Function`) is checked against a non-function value such as an Int, String, Listing, Mapping, or null.

Common situations: Assigning a number/string where a callback is expected; a base-module or stdlib property expecting a function receiving a plain value; confusion between a function's result and the function itself (writing `f()` instead of `f`).

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


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/691d48cdca06cbff. Report an issue: GitHub.