xai-org/x-algorithm · error · SemanticCheckFailure

Mock function expects either 1 or 3 arguments but %d receive

Error message

Mock function expects either 1 or 3 arguments but %d received

What it means

The Mock(...) testing construct accepts exactly 1 argument (function name) or 3 arguments (name, variable, body). Any other child count is rejected before the mock is registered.

Source

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

        ASTNode bodyNode = createASTNodeTree(context, root.getChild(2));
        context.addMock(funcName, bodyNode);
      } else if (root.getChildCount() == 4) {
        for (int i = 1; i < root.getChildCount() - 1; i++) {
          String funcName = toStringConstant(root.getChild(1));
          String variableName = getVariableName(root.getChild(2));
          Type variableType = Type.listOf(Type.OBJECT);

          CompilerScope scope = context.addScope();
          Parameter parameter = Parameter.open(variableName, variableType);
          scope.defineVariable(parameter);

          ASTNode bodyNode = createASTNodeTree(context, root.getChild(3));
          context.removeScope();

          context.addMock(funcName, variableName, bodyNode);
        }
      } else {
        throw new SemanticCheckFailure(
            String.format("Mock function expects either 1 or 3 arguments but %d received",
                root.getChildCount() - 1)
        );
      }
    } catch (Exception e) {
      throw new SemanticCheckFailure(e);
    }

    return Constant.UNIT;
  }

  private ASTNode toMockPass(
      CompilerContext context,
      String exprText,
      Tree root) throws SemanticCheckFailure {
    try {
      if (root.getChildCount() == 2) {
        String funcName = toStringConstant(root.getChild(1));

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Use either Mock(fnName) or Mock(fnName, varName, bodyExpr) exactly
  2. Remove extra arguments or add the missing variable/body pair

Example fix

// before
Mock("getScore", ToDouble(0.0))
// after
Mock("getScore", "x", ToDouble(0.0))
Defensive patterns

Strategy: validation

Validate before calling

int n = mockArgCount;
if (n != 1 && n != 3) throw new IllegalArgumentException("Mock needs 1 or 3 args, got " + n);

Try / catch

catch (SemanticCheckFailure e) { if (e.getMessage().contains("Mock function expects")) fixMockShape(); else throw e; }

Prevention

When it happens

Trigger: `Mock("fn")` (valid), `Mock("fn", "x", expr)` (valid), but `Mock()` or `Mock("fn", expr)` fails with the received count.

Common situations: Writing test mocks by hand with the wrong shape, or copy-pasting between Mock and MockPass forms and miscounting arguments.

Related errors


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