{"record":{"id":"691d48cdca06cbff","repo":"apple/pkl","slug":"type-mismatch-value-is-not-of-type-function","errorCode":null,"errorMessage":"type mismatch: value is not of type Function","messagePattern":"type mismatch: value is not of type Function","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":2076,"sourceCode":"\n    public final VmList getTypeArgumentMirrors() {\n      return VmList.of(typeArgumentNode.getMirror());\n    }\n\n    @Override\n    protected final PType doExport() {\n      return new PType.Class(BaseModule.getFunctionClass().export(), typeArgumentNode.doExport());\n    }\n\n    @Specialization\n    protected Object eval(VmFunction value) {\n      /* do nothing */\n      return value;\n    }\n\n    @Fallback\n    protected void fallback(Object value) {\n      throw typeMismatch(value, BaseModule.getFunctionClass());\n    }\n\n    @Override\n    public boolean doIsEquivalentTo(TypeNode other) {\n      if (!(other instanceof FunctionClassTypeNode functionClassTypeNode)) {\n        return false;\n      }\n      return typeArgumentNode.isEquivalentTo(functionClassTypeNode.typeArgumentNode);\n    }\n\n    @Override\n    protected boolean acceptTypeNode(boolean visitTypeArguments, TypeNodeConsumer consumer) {\n      return consumer.accept(this);\n    }\n\n    @Override\n    protected boolean isParametric() {\n      return true;","sourceCodeStart":2058,"sourceCodeEnd":2094,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L2058-L2094","documentation":"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.","triggerScenarios":"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.","commonSituations":"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`).","solutions":["Supply an actual function value (e.g. `(n) -> n * 2`) where the function type is required.","Correct the type annotation if the property is not meant to be a function type."],"exampleFix":"// before\ntransform: Function = value * 2\n\n// after\ntransform: Function = (v) -> v * 2","handlingStrategy":"type-guard","validationCode":"if (value is Function) { /* ok */ } else { throw \"expected a function\" }","typeGuard":"function isFunction(v: Any): Boolean = v is Function","tryCatchPattern":"// catch VmTypeMismatchException.Simple around evaluation and report the failing property\ntry { evalTypeCheck() } catch (e: VmTypeMismatchException) { report(e.sourceSection, e) }","preventionTips":["Never assign literals (Int/String/null) to Function-typed properties.","Don't call the function (drop `()`) when passing it as a value.","Check imported/generated values' declared types before binding."],"tags":["pkl","type-mismatch","function-type"],"backgroundTag":"type-mismatch","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}