{"record":{"id":"2c22c349bb8bdada","repo":"xai-org/x-algorithm","slug":"structtuple-expects-pairs-of-name-and-values-but","errorCode":null,"errorMessage":"StructTuple expects pairs of name and values, but a %s received","messagePattern":"StructTuple expects pairs of name and values, but a (.+?) received","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/CompilerUnit.java","lineNumber":276,"sourceCode":"      @Override\n      public BotMakerDoc botMakerDoc() {\n        return description;\n      }\n\n      @Override\n      public Fingerprint fingerprint() {\n        return Fingerprint.EMPTY;\n      }\n\n      @Override\n      public ASTNode createASTNode(ImmutableList<ASTNode> children) throws SemanticCheckFailure {\n\n        ImmutableList<String> fieldNames = structTupleType.fieldNames;\n        ASTNode[] fieldValues = new ASTNode[fieldNames.size()];\n\n        for (ASTNode child : children) {\n          if (!(child instanceof ToPair)) {\n            throw new SemanticCheckFailure(\n                String.format(\n                    \"StructTuple expects pairs of name and values, but a %s received\", child)\n            );\n          }\n\n          String fieldName = ((Constant) child.getChildren().get(0)).getValue().toString();\n          if (!fieldNames.contains(fieldName)) {\n            throw new SemanticCheckFailure(\n                String.format(\"Field %s does not belong to %s\", fieldName, toString())\n            );\n          }\n          fieldValues[fieldNames.indexOf(fieldName)] = (ASTNode) child.getChildren().get(1);\n        }\n        return new ToStructTuple(fn, fieldNames, ImmutableList.copyOf(fieldValues)) {\n          @Override\n          public Signature getSignature() {\n            return signature;\n          }","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/CompilerUnit.java#L258-L294","documentation":"When constructing a StructTuple node, every child must be a ToPair (name, value) mapping a field name to its value. Any other child node type (a bare constant, function call, etc.) is rejected with this error.","triggerScenarios":"Passing non-pair children to a struct-tuple constructor in the DSL, e.g. 'StructType(value1, value2)' instead of 'StructType(field = value1, other = value2)', so a child ASTNode is not an instance of ToPair.","commonSituations":"Writing struct literals positionally instead of by field name; DSL syntax changes; generated code emitting bare expressions inside struct constructors.","solutions":["Rewrite the struct literal using field=value pairs for every field","Check the struct's expected fields and provide each as a named pair","If generating code, emit ToPair nodes for each field"],"exampleFix":"// before\nMyStruct(a, b)\n// after\nMyStruct(field1 = a, field2 = b)","handlingStrategy":"validation","validationCode":"for (ASTNode c : children) if (!(c instanceof ToPair)) throw new IllegalArgumentException(\"StructTuple children must be name=value pairs\");","typeGuard":"boolean isFieldPair(ASTNode n) { return n instanceof ToPair; }","tryCatchPattern":"catch (SemanticCheckFailure e) { /* rewrite struct literal as field=value pairs */ }","preventionTips":["Always construct struct literals with explicit field names","Lint generated code for bare children in struct constructors"],"tags":["botmaker","struct","constructor","syntax"],"backgroundTag":"invalid-constructor-arguments","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}