xai-org/x-algorithm · error · SemanticCheckFailure

Derived Feature %s has %d parameters, received %d

Error message

Derived Feature %s has %d parameters, received %d

What it means

A derived feature call must supply an argument for every parameter, except trailing parameters that have defaults. The error fires when too many arguments are given, or a skipped parameter has no default value.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java:1170

    Optional<DerivedFeature> dfOpt = context.getDerivedFeature(funcName);
    if (!dfOpt.isPresent()) {
      throw new SemanticCheckFailure(String.format(
          "%s is not a derived feature function", funcName));
    }

    DerivedFeature derivedFeature = dfOpt.get();
    context.trackUsage(derivedFeature);

    List<Tuple3<Tree, String, Optional<Tree>>> params = derivedFeature.getParams();
    boolean isLogged = derivedFeature.isLogged();

    List<ASTNode> args = children;
    if (params.size() != children.size()) {

      if (params.size() < children.size()
          || !params.get(children.size()).getThird().isPresent()) {
        throw new SemanticCheckFailure(String.format(
            "Derived Feature %s has %d parameters, received %d",
            funcName, params.size(), children.size()));
      }

      ImmutableList.Builder<ASTNode> builder = ImmutableList.builder();
      builder.addAll(children);
      for (int i = children.size(); i < params.size(); i++) {
        Tree tree = params.get(i).getThird().get();
        ASTNode child = createASTNodeTree(context, tree);
        builder.add(child);
      }
      args = builder.build();
    }

    List<Pair<String, ASTNode>> variables = Lists.newArrayListWithCapacity(params.size());
    context.addScope();
    for (int i = 0; i < params.size(); i++) {
      String paramName = params.get(i).getSecond();

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Match the call's argument count to the declared parameter list
  2. Add default values to optional parameters in the derived feature declaration, or always pass them explicitly
  3. Update stale call sites after signature changes

Example fix

// before
derived feature greet(name, punctuation = ".") = ...
value = greet("hi", "!", "?")
// after
value = greet("hi", "!")
Defensive patterns

Strategy: validation

Validate before calling

if (args.size() > params.size() || (args.size() < params.size() && !params.get(args.size()).hasDefault()))
  throw new IllegalArgumentException("Arity mismatch for " + funcName);

Try / catch

catch (SemanticCheckFailure e) { if (e.getMessage().contains("parameters, received")) reportArity(e); else throw e; }

Prevention

When it happens

Trigger: Calling df(a, b, c) when df has 2 params; or calling df(a) when df has 2 params and the second lacks a default (params.size() > children.size() and the first missing param has no default).

Common situations: Signature drift after adding/removing a parameter without updating call sites, or assuming a parameter is optional when no default was declared.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/29ad9fd892a0f3ba. Report an issue: GitHub.