{"record":{"id":"b8aeec0eaab0e98b","repo":"xai-org/x-algorithm","slug":"s-s-already-exists-in-the-same-scope-and-is-defi","errorCode":null,"errorMessage":"%s %s already exists in the same scope and is defined differently","messagePattern":"(.+?) (.+?) already exists in the same scope and is defined differently","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/CompilerScope.java","lineNumber":51,"sourceCode":"  }\n\n  Map<String, Parameter> getVariables() {\n    return variables;\n  }\n\n  private static <T>  void checkAndMergeMap(\n      Map<String, T> thisMap,\n      Map<String, T> thatMap,\n      String elementName,\n      BiPredicate<T, T> predicate\n  ) throws SemanticCheckFailure {\n    for (Map.Entry<String, T> entry : thatMap.entrySet()) {\n      if (!thisMap.containsKey(entry.getKey())) {\n        thisMap.put(entry.getKey(), entry.getValue());\n        continue;\n      }\n      if (predicate.test(thisMap.get(entry.getKey()), entry.getValue())) {\n        throw new SemanticCheckFailure(String.format(\n            \"%s %s already exists in the same scope and is defined differently\",\n            elementName, entry.getKey()));\n      }\n    }\n  }\n\n  public void mergeTypes(CompilerScope that) throws SemanticCheckFailure {\n    checkAndMergeMap(\n            this.thriftTypes,\n            that.thriftTypes,\n            \"thrift type\",\n            ThriftType.EQUALITY_CHECK\n    );\n    checkAndMergeMap(\n            this.thriftStructTypes,\n            that.thriftStructTypes,\n            \"thrift struct type\",\n            ThriftStructType.EQUALITY_CHECK","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/CompilerScope.java#L33-L69","documentation":"When merging two scopes (e.g. merging type or variable maps from another scope), a key present in both maps but with differing definitions fails the equality predicate and aborts the merge. This prevents silently overwriting a conflicting definition.","triggerScenarios":"mergeTypes/mergeVirtualContext encountering the same type alias or variable name defined differently in the two scopes being combined — e.g. two imports aliasing the same name to different thrift types, or a virtual context clashing with an existing definition.","commonSituations":"Merging module scopes that both import 'T' from different sources; combining contexts in a larger composition; refactors that introduce duplicate aliases.","solutions":["Rename one of the conflicting aliases so both can coexist","Make the definitions identical (import the same underlying type/variable)","Drop the redundant definition from one scope before merging"],"exampleFix":"// before\nscopeA: import A.T as X; scopeB: import B.T as X  // clash\n// after\nscopeA: import A.T as X; scopeB: import B.T as Y","handlingStrategy":"validation","validationCode":"for (String k : mapA.keySet()) if (mapB.containsKey(k) && !equal(mapA.get(k), mapB.get(k))) throw new IllegalStateException(\"conflicting definition: \" + k);","typeGuard":null,"tryCatchPattern":"catch (SemanticCheckFailure e) { /* rename one conflicting alias */ }","preventionTips":["Use unique alias names per module","Fail fast on duplicate aliases during import, not at merge time"],"tags":["botmaker","scope-merge","conflicting-definition"],"backgroundTag":"duplicate-symbol-conflict","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}