{"record":{"id":"239252d101f9757a","repo":"apple/pkl","slug":"wrongtypeargumentcount-239252","errorCode":"wrongTypeArgumentCount","errorMessage":"wrongTypeArgumentCount","messagePattern":"wrongTypeArgumentCount","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/UnresolvedTypeNode.java","lineNumber":343,"sourceCode":"        for (var i = 0; i < argLength; i++) {\n          resolvedTypeArgumentNodes[i] = typeArgumentNodes[i].execute(frame);\n        }\n        return new TypeAliasTypeNode(sourceSection, typeAlias, resolvedTypeArgumentNodes);\n      }\n\n      var module = (VmTyped) baseType;\n      throw exceptionBuilder()\n          .evalError(\"notAParameterizableClass\", module.getModuleInfo().getModuleName())\n          .withSourceSection(typeArgumentNodes[0].sourceSection)\n          .build();\n    }\n\n    private void checkNumberOfTypeArguments(VmClass clazz) {\n      var expectedCount = clazz.getTypeParameterCount();\n      var actualCount = typeArgumentNodes.length;\n      if (expectedCount != actualCount) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder()\n            .evalError(\"wrongTypeArgumentCount\", expectedCount, actualCount)\n            .build();\n      }\n    }\n  }\n\n  public static final class Nullable extends UnresolvedTypeNode {\n    @Child private UnresolvedTypeNode elementTypeNode;\n\n    public Nullable(SourceSection sourceSection, UnresolvedTypeNode elementTypeNode) {\n      super(sourceSection);\n      this.elementTypeNode = elementTypeNode;\n    }\n\n    @Override\n    public TypeNode execute(VirtualFrame frame) {\n      CompilerDirectives.transferToInterpreter();\n","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/UnresolvedTypeNode.java#L325-L361","documentation":"Raised by `UnresolvedTypeNode.Parameterized#checkNumberOfTypeArguments` (called from `execute`): a parameterized class annotation was given a different number of type arguments than the class declares. The `wrongTypeArgumentCount` error reports the expected and actual counts. An interpreter-to-compiler transition precedes the throw, so this is a definite static-usage error in the annotation.","triggerScenarios":"e.g. `Map<String>` (needs 2), `List<A, B>` (needs 1), or `Function1<A>` (needs 2: param + return) — any mismatch between `clazz.getTypeParameterCount()` and the number of `<...>` arguments written.","commonSituations":"Forgetting the value type in `Map<K,V>`; omitting the return type of `FunctionN`; adding a variance/default argument out of habit from other languages; refactoring a class to add/remove type parameters without updating usages.","solutions":["Supply the exact number of type arguments the error reports as expected (e.g. `Map<String, Int>`).","For functions, include all parameters plus the return type: `Function1<String, Boolean>`.","Update all usages after changing a class's type-parameter list.","Check the class declaration for its `typeParameterCount` to confirm."],"exampleFix":"// before\nbyName: Map<String> = Map()\n// after\nbyName: Map<String, Person> = Map()","handlingStrategy":"validation","validationCode":"function assertTypeArgCount(cls, args) {\n  if (args.length !== cls.typeParameterCount) {\n    throw new Error(`${cls.name} expects ${cls.typeParameterCount} type arguments, got ${args.length}`);\n  }\n}","typeGuard":"function hasCorrectArity(cls, args) { return cls && args && args.length === cls.typeParameterCount; }","tryCatchPattern":"try {\n  buildParameterizedType(cls, args);\n} catch (e) {\n  // correct arity and rebuild\n}","preventionTips":["Memorize arities of core generics: Map<K,V>=2, List<T>=1, FunctionN = N+1.","Update all call/annotation sites when changing a class's type parameters.","Use IDE type checking before evaluation."],"tags":["pkl","generics","arity","type-arguments"],"backgroundTag":"missing-required-argument","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}