xai-org/x-algorithm · error · SemanticCheckFailure

Copy function only supports Map or StructTuple.

Error message

Copy function only supports Map or StructTuple.

What it means

Copy() only works on values whose return type is map-like or struct-tuple-like. When the first argument's type is neither (e.g. a List, String, or scalar), Copy.of throws SemanticCheckFailure at build time.

Source

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

  }

  @Override
  protected CacheLevel getCacheLevel() {
    return CacheLevel.Global;
  }

  public static Copy of(ImmutableList<ASTNode> children) throws SemanticCheckFailure {
    if (children.size() < 1) {
      throw new SemanticCheckFailure("expects at least one argument.");
    }

    Type nodeType = children.get(0).getReturnType();
    if (nodeType.mapLike()) {
      return ofMap(children);
    } else if (nodeType.structTupleLike()) {
      return ofStructTuple(children);
    } else {
      throw new SemanticCheckFailure("Copy function only supports Map or StructTuple.");
    }

  }

  private static Copy ofMap(ImmutableList<ASTNode> children) throws SemanticCheckFailure {

    for (int i = 1; i < children.size(); i++) {
      if (!children.get(i).getReturnType().pairLike()) {
        throw new SemanticCheckFailure(String.format(
            "expects a Pair argument but get %s.", children.get(i).getReturnType())
        );
      }
    }

    Signature signature = new Signature(
        ImmutableList.of(Type.mapOf(TPA, TPB)),
        Type.pairOf(TPA, TPB),
        Type.mapOf(TPA, TPB)

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Use map/struct-tuple producing functions (e.g. ToStructTuple, ToMap) to build the first argument
  2. For lists use a list-specific copy/slice function such as Slice
  3. Verify the first argument's return type with type introspection before building Copy

Example fix

// before
Copy(myList, 0: "a")
// after
Copy(myMap, key: "value")
Defensive patterns

Strategy: type-guard

Validate before calling

// rule-language: ensure the first arg is map/struct-like
Copy(ToMap(x), k: v)

Type guard

// host code
Type t = children.get(0).getReturnType();
if (!t.mapLike() && !t.structTupleLike()) { /* pick a different function */ }

Prevention

When it happens

Trigger: Calling Copy(someList, ...), Copy("text", ...), or Copy(42, ...) where the first child is not a Map or StructTuple type.

Common situations: Assuming Copy deep-copies lists or strings; refactoring a rule so the first argument changed from a map to another type.

Related errors


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