{"record":{"id":"68a6b3bf277da2bd","repo":"xai-org/x-algorithm","slug":"parameter-s-type-s-is-not-compatible-with-th","errorCode":null,"errorMessage":"Parameter [%s] type [%s] is not compatible with the default value type [%s]","messagePattern":"Parameter \\[(.+?)\\] type \\[(.+?)\\] is not compatible with the default value type \\[(.+?)\\]","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/CompilerContext.java","lineNumber":143,"sourceCode":"        Parser.createParseParamsTree(expression);\n    return compile(result.getFirst(), result.getSecond(), result.getThird());\n  }\n\n  private ASTNode<E> compile(\n      Tree tree,\n      ImmutableList<Tuple3<Tree, String, Optional<Tree>>> params,\n      Optional<Tree> returnType)\n      throws ParseFailure, SemanticCheckFailure {\n    if (params.size() > 0) {\n      CompilerScope rootScope = addScope();\n      for (Tuple3<Tree, String, Optional<Tree>> param : params) {\n        String paramName = param.getSecond();\n        Type paramType = TypeCompiler.getType(param.getFirst(), currentScope());\n        rootScope.defineVariable(Parameter.of(paramName, paramType));\n        if (param.getThird().isPresent()) {\n          ASTNode<E> node = compiler.createASTNodeTree(this, param.getThird().get());\n          if (Type.isDivergentTo(paramType, node.getReturnType())) {\n            throw new SemanticCheckFailure(String.format(\n                \"Parameter [%s] type [%s] is not compatible with the default value type [%s]\",\n                paramName,\n                paramType.toString(),\n                node.getReturnType().toString()\n            ));\n          }\n        }\n      }\n    }\n\n    ASTNode<E> astNode = compiler.createASTNodeTree(this, tree);\n    if (returnType.isPresent()) {\n      Type claimedType = TypeCompiler.getType(returnType.get(), currentScope());\n      if (Type.isDivergentTo(claimedType, astNode.getReturnType())) {\n        throw new SemanticCheckFailure(String.format(\n            \"ASTNode return type [%s] is not compatible with the claimed return type [%s]\",\n            astNode.getReturnType().toString(),\n            claimedType.toString()));","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/CompilerContext.java#L125-L161","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nparam: (long, \"x\", Some(parseTree(\"'str'\"))) // default is a string\n// after\nparam: (long, \"x\", Some(parseTree(\"42L\")))","handlingStrategy":"validation","validationCode":"Type defaultType = compiler.createASTNodeTree(ctx, defaultTree).getReturnType();\nif (Type.isDivergentTo(paramType, defaultType)) throw new IllegalArgumentException(\"default type mismatch\");","typeGuard":null,"tryCatchPattern":"catch (SemanticCheckFailure e) { /* surface param name and both types from message */ }","preventionTips":["Keep parameter types and defaults adjacent and review them together","Type-check defaults in unit tests of compiler units"],"tags":["botmaker","type-check","default-value","parameter"],"backgroundTag":"type-mismatch-assignment","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}