xai-org/x-algorithm · error · SemanticCheckFailure
Parameter [%s] type [%s] is not compatible with the default
Error message
Parameter [%s] type [%s] is not compatible with the default value type [%s]
What it means
When compiling a function parameter that has a default value expression, the compiler evaluates the default's return type and rejects it if it diverges from the declared parameter type. This enforces type safety of default arguments at compile time.
Source
Thrown at botmaker/src/java/com/twitter/botmaker/compiler/CompilerContext.java:143
Parser.createParseParamsTree(expression);
return compile(result.getFirst(), result.getSecond(), result.getThird());
}
private ASTNode<E> compile(
Tree tree,
ImmutableList<Tuple3<Tree, String, Optional<Tree>>> params,
Optional<Tree> returnType)
throws ParseFailure, SemanticCheckFailure {
if (params.size() > 0) {
CompilerScope rootScope = addScope();
for (Tuple3<Tree, String, Optional<Tree>> param : params) {
String paramName = param.getSecond();
Type paramType = TypeCompiler.getType(param.getFirst(), currentScope());
rootScope.defineVariable(Parameter.of(paramName, paramType));
if (param.getThird().isPresent()) {
ASTNode<E> node = compiler.createASTNodeTree(this, param.getThird().get());
if (Type.isDivergentTo(paramType, node.getReturnType())) {
throw new SemanticCheckFailure(String.format(
"Parameter [%s] type [%s] is not compatible with the default value type [%s]",
paramName,
paramType.toString(),
node.getReturnType().toString()
));
}
}
}
}
ASTNode<E> astNode = compiler.createASTNodeTree(this, tree);
if (returnType.isPresent()) {
Type claimedType = TypeCompiler.getType(returnType.get(), currentScope());
if (Type.isDivergentTo(claimedType, astNode.getReturnType())) {
throw new SemanticCheckFailure(String.format(
"ASTNode return type [%s] is not compatible with the claimed return type [%s]",
astNode.getReturnType().toString(),
claimedType.toString()));View on GitHub (pinned to 24c60942c5)
Solutions
- Align the default value expression's type with the declared parameter type
- Change the declared parameter type to match what the default expression actually returns
- Wrap or convert the default expression (cast/coerce function) so its return type matches
Example fix
// before
param: (long, "x", Some(parseTree("'str'"))) // default is a string
// after
param: (long, "x", Some(parseTree("42L"))) Defensive patterns
Strategy: validation
Validate before calling
Type defaultType = compiler.createASTNodeTree(ctx, defaultTree).getReturnType();
if (Type.isDivergentTo(paramType, defaultType)) throw new IllegalArgumentException("default type mismatch"); Try / catch
catch (SemanticCheckFailure e) { /* surface param name and both types from message */ } Prevention
- Keep parameter types and defaults adjacent and review them together
- Type-check defaults in unit tests of compiler units
When it happens
Trigger: Defining a parameter with an explicit type (e.g. long) but supplying a default expression whose inferred type is incompatible (e.g. a string literal or a function returning a different type), so Type.isDivergentTo(paramType, node.getReturnType()) is true.
Common situations: Changing a parameter's declared type without updating its default; passing a nullable/optional default where a concrete type is declared; type alias mismatches after thrift schema changes.
Related errors
- class to be imported has to be either a TBase or ThriftStruc
- Sort expects a collection of %s objects, but gets %s
- ASTNode return type [%s] is not compatible with the claimed
- unrecognized function name:
- cannot find class %s
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/68a6b3bf277da2bd.
Report an issue: GitHub.