{"record":{"id":"e8366a52cbba6a5c","repo":"xai-org/x-algorithm","slug":"type-checking-expression-s-failed-expects-2-argu","errorCode":null,"errorMessage":"type checking expression %s failed: expects 2 arguments, %d passed","messagePattern":"type checking expression (.+?) failed: expects 2 arguments, (.+?) passed","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/function/math/ArithmeticOperation.java","lineNumber":145,"sourceCode":"    return new ArithmeticOperation<T>(exprText, children) {\n      @Override\n      public Signature getSignature() {\n        return signature;\n      }\n\n      @Override\n      protected Object apply(Context<Runtime> context, T numA, T numB) {\n        return function.apply(context, numA, numB);\n      }\n    };\n  }\n\n  private static void validateSignature(\n      String exprText,\n      ImmutableList<ASTNode> children\n  ) throws SemanticCheckFailure {\n    if (children.size() != 2) {\n      throw new SemanticCheckFailure(String.format(\n          \"type checking expression %s failed: expects 2 arguments, %d passed\",\n          exprText,\n          children.size()\n      ));\n    }\n  }\n\n  public static ArithmeticOperation ofSum(String exprText, ImmutableList<ASTNode> children)\n      throws SemanticCheckFailure {\n    validateSignature(exprText, children);\n    if (children.get(0).getReturnType().longLike()\n        && children.get(1).getReturnType().longLike()) {\n      return of(exprText, children, LONG_SIGNATURE, ADD_FUNCTION);\n    } else if (children.get(0).getReturnType().stringLike()\n        && children.get(1).getReturnType().stringLike()) {\n      return of(exprText, children, STRING_SIGNATURE, CONCAT_FUNCTION);\n    } else {\n      return of(exprText, children, DOUBLE_SIGNATURE, ADD_FUNCTION);","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/function/math/ArithmeticOperation.java#L127-L163","documentation":"ArithmeticOperation.validateSignature throws SemanticCheckFailure during semantic checking when an arithmetic expression node (+, -, etc. built via ofSum or sibling factories) does not have exactly 2 children. Binary arithmetic operators are strictly two-operand; malformed ASTs are rejected before evaluation.","triggerScenarios":"Building an ASTNode for sum/subtraction with 1 or 3+ children, e.g. calling ofSum with an ImmutableList of children whose size != 2, or hand-constructing arithmetic nodes from parsed fragments.","commonSituations":"Custom AST construction, expression parser bugs producing malformed trees, or refactorings that change child counts of binary operators.","solutions":["Fix the AST construction so the arithmetic node gets exactly 2 children","If you intended n-ary summation, use Sum()/an n-ary function instead of the binary ofSum","Add a unit assertion on children.size() when building binary nodes to catch this early"],"exampleFix":"// before\nArithmeticOperation.ofSum(node, ImmutableList.of(a)); // 1 child -> failure\n// after\nArithmeticOperation.ofSum(node, ImmutableList.of(a, b)); // exactly 2\n","handlingStrategy":"validation","validationCode":"if (children.size() != 2) {\n  throw new IllegalArgumentException(\"arithmetic node needs exactly 2 operands: \" + children);\n}\nArithmeticOperation.ofSum(node, children);","typeGuard":null,"tryCatchPattern":"try {\n  return ArithmeticOperation.ofSum(node, children);\n} catch (SemanticCheckFailure e) {\n  throw new IllegalStateException(\"malformed arithmetic expression: \" + exprText, e);\n}","preventionTips":["Centralize binary-node construction in one builder that asserts child count","Use n-ary Sum() for variadic arithmetic","Fuzz-test the expression parser for operand-count invariant"],"tags":["semantic-check","arithmetic","ast","validation"],"backgroundTag":"semantic-check-failed","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}