{"record":{"id":"9e9fe65ebbf6db3a","repo":"xai-org/x-algorithm","slug":"copy-function-only-supports-map-or-structtuple","errorCode":null,"errorMessage":"Copy function only supports Map or StructTuple.","messagePattern":"Copy function only supports Map or StructTuple\\.","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/function/collection/Copy.java","lineNumber":49,"sourceCode":"  }\n\n  @Override\n  protected CacheLevel getCacheLevel() {\n    return CacheLevel.Global;\n  }\n\n  public static Copy of(ImmutableList<ASTNode> children) throws SemanticCheckFailure {\n    if (children.size() < 1) {\n      throw new SemanticCheckFailure(\"expects at least one argument.\");\n    }\n\n    Type nodeType = children.get(0).getReturnType();\n    if (nodeType.mapLike()) {\n      return ofMap(children);\n    } else if (nodeType.structTupleLike()) {\n      return ofStructTuple(children);\n    } else {\n      throw new SemanticCheckFailure(\"Copy function only supports Map or StructTuple.\");\n    }\n\n  }\n\n  private static Copy ofMap(ImmutableList<ASTNode> children) throws SemanticCheckFailure {\n\n    for (int i = 1; i < children.size(); i++) {\n      if (!children.get(i).getReturnType().pairLike()) {\n        throw new SemanticCheckFailure(String.format(\n            \"expects a Pair argument but get %s.\", children.get(i).getReturnType())\n        );\n      }\n    }\n\n    Signature signature = new Signature(\n        ImmutableList.of(Type.mapOf(TPA, TPB)),\n        Type.pairOf(TPA, TPB),\n        Type.mapOf(TPA, TPB)","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/function/collection/Copy.java#L31-L67","documentation":"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.","triggerScenarios":"Calling Copy(someList, ...), Copy(\"text\", ...), or Copy(42, ...) where the first child is not a Map or StructTuple type.","commonSituations":"Assuming Copy deep-copies lists or strings; refactoring a rule so the first argument changed from a map to another type.","solutions":["Use map/struct-tuple producing functions (e.g. ToStructTuple, ToMap) to build the first argument","For lists use a list-specific copy/slice function such as Slice","Verify the first argument's return type with type introspection before building Copy"],"exampleFix":"// before\nCopy(myList, 0: \"a\")\n// after\nCopy(myMap, key: \"value\")","handlingStrategy":"type-guard","validationCode":"// rule-language: ensure the first arg is map/struct-like\nCopy(ToMap(x), k: v)","typeGuard":"// host code\nType t = children.get(0).getReturnType();\nif (!t.mapLike() && !t.structTupleLike()) { /* pick a different function */ }","tryCatchPattern":null,"preventionTips":["Use Copy only for Map and StructTuple values","Use Slice/list functions for lists"],"tags":["botmaker","semantic-check","type-mismatch","copy"],"backgroundTag":"function-argument-type-mismatch","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}