xai-org/x-algorithm · error · SemanticCheckFailure
Type does not support index accessor
Error message
Type %s does not support index accessor
What it means
The index accessor (expr[index]) supports Lists, Lists of Pairs, two-param Maps, and untyped Object expressions. Applying an index to any other static return type (e.g. Long, Boolean, StructTuple with different arity) fails semantic checking with this message.
Solutions
- Access struct fields with the appropriate field-access function instead of index syntax
- Ensure maps are typed with exactly two type params (K, V)
- Cast the expression to Object before indexing when the runtime type is genuinely indexable
Example fix
// before someScalar[0] // after Get(someList, 0)
Defensive patterns
Strategy: type-guard
Validate before calling
// rule-language: use explicit accessors per type Get(list, 0) / GetByKey(map, key)
Type guard
// host code before mkIndexAccessor
Type rt = exprNode.getReturnType();
boolean supports = rt.getBase().equals(List.class)
|| (rt.getBase().equals(Map.class) && rt.getTypeParams().size() == 2)
|| rt.getBase().equals(Object.class); Prevention
- Only index Lists, 2-param Maps, and Object-typed expressions
- Use field accessors for structs
When it happens
Trigger: Writing myLong[0], myStruct['field'], or map[key] where the map's type params are not exactly 2.
Common situations: Using struct field syntax on a non-map, indexing a scalar returned by a previous function, or a typed map whose type parameters were lost/added.
Related errors
- Contains expects input of String, Map, Set or Collection…
- Copy function only supports Map or StructTuple.
- Count expects input of String, Map or Collection types but
- expecting the input to be of String or List type but…
- Sort expects a collection of
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/dab1e28f0b059bcb.
Report an issue: GitHub.
Appendix: source
Thrown at botmaker/src/java/com/twitter/botmaker/function/collection/IndexAccessor.java:47
public static ASTNode mkIndexAccessor(
String exprText, ASTNode exprNode, ASTNode indexNode) throws SemanticCheckFailure {
Type returnType = exprNode.getReturnType();
Type indextype = indexNode.getReturnType();
if (returnType.getBase().equals(List.class)
&& returnType.getTypeParams().size() == 1
&& indextype.equals(Type.pairOf(Type.LONG, Type.LONG))) {
return listPairAccessor(exprText, exprNode, indexNode);
} else if (returnType.getBase().equals(List.class)
&& returnType.getTypeParams().size() == 1) {
return listIndexAccessor(exprText, exprNode, indexNode);
} else if (returnType.getBase().equals(Map.class)
&& returnType.getTypeParams().size() == 2) {
return mapKeyAccessor(exprText, exprNode, indexNode);
} else if (returnType.getBase().equals(Object.class)) {
return objectIndexAccessor(exprText, exprNode, indexNode);
} else {
throw new SemanticCheckFailure(
String.format("Type %s does not support index accessor", returnType));
}
}
private static ASTNode listPairAccessor(
String exprText, ASTNode exprNode, ASTNode indexNode) throws SemanticCheckFailure {
Type returnType = exprNode.getReturnType();
Type indextype = indexNode.getReturnType();
Signature signature = new Signature(
ImmutableList.of(returnType, indextype),
returnType);
return new IndexAccessor(exprText, ImmutableList.of(exprNode, indexNode)) {
@Override
public Signature getSignature() {
return signature;
}View on GitHub (pinned to 24c60942c5)