xai-org/x-algorithm · error · SemanticCheckFailure

StructTuple field %s expects type %s, but %s received.

Error message

StructTuple field %s expects type %s, but %s received.

What it means

When Copy() overrides a StructTuple field, the override value's type must be divergent-compatible with the field's declared type. If the field was already defined (matching by name) and the new value's type is incompatible, semantic checking fails naming the field, expected type, and received type.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/function/collection/Copy.java:136

        throw new SemanticCheckFailure(
            String.format("expects <name>: <value> pairs, but a %s received", child));
      }

      String fieldName = ((Constant) child.getChildren().get(0)).getValue().toString();
      Type fieldType = ((ASTNode) child.getChildren().get(1)).getReturnType();

      argBuilder.add((ASTNode) child.getChildren().get(1));
      argTypeBuilder.add(fieldType);

      int fieldIndex = fieldNames.indexOf(fieldName);
      if (fieldIndex < 0) {
        fieldNames.add(fieldName);
        fieldTypes.add(fieldType);
        overriddenFieldIndices[i] = fieldNames.size() - 1;
      } else if (!Type.isDivergentTo(fieldTypes.get(fieldIndex), fieldType)) {
        overriddenFieldIndices[i] = fieldIndex;
      } else {
        throw new SemanticCheckFailure(
            String.format("StructTuple field %s expects type %s, but %s received.",
                fieldName, fieldTypes.get(fieldIndex), fieldType)
        );
      }
    }

    StructTupleType returnType = Type.structTupleOf(
        ImmutableList.copyOf(fieldNames),
        ImmutableList.copyOf(fieldTypes)
    );

    Signature signature = new Signature(
        argTypeBuilder.build(),
        returnType
    );

    return new Copy("Copy", argBuilder.build()) {

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Match the override value's type to the struct field's declared type (e.g. use numeric literals for Long fields)
  2. Check the struct's field type definitions and cast/coerce the value accordingly
  3. Remove duplicate field overrides that conflict in type

Example fix

// before
Copy(user, age: "42")
// after
Copy(user, age: 42)
Defensive patterns

Strategy: validation

Validate before calling

// host code: verify override types match declared field types
Type declared = structType.getFields().get(fieldName);
if (!Type.isDivergentTo(declared, overrideType)) {
  throw new IllegalArgumentException(fieldName + " expects " + declared);
}

Prevention

When it happens

Trigger: Copy(struct, age: "not a number") where age is declared Long; duplicating a field name with a differently-typed value in the same Copy call (first occurrence defines the type, later incompatible ones fail).

Common situations: Passing a string constant for a numeric field, null-typed values, or copying fields between structs with slightly different schemas.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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