xai-org/x-algorithm · error · SemanticCheckFailure

%s %s already exists in the same scope and is defined differ

Error message

%s %s already exists in the same scope and is defined differently

What it means

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.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/CompilerScope.java:51

  }

  Map<String, Parameter> getVariables() {
    return variables;
  }

  private static <T>  void checkAndMergeMap(
      Map<String, T> thisMap,
      Map<String, T> thatMap,
      String elementName,
      BiPredicate<T, T> predicate
  ) throws SemanticCheckFailure {
    for (Map.Entry<String, T> entry : thatMap.entrySet()) {
      if (!thisMap.containsKey(entry.getKey())) {
        thisMap.put(entry.getKey(), entry.getValue());
        continue;
      }
      if (predicate.test(thisMap.get(entry.getKey()), entry.getValue())) {
        throw new SemanticCheckFailure(String.format(
            "%s %s already exists in the same scope and is defined differently",
            elementName, entry.getKey()));
      }
    }
  }

  public void mergeTypes(CompilerScope that) throws SemanticCheckFailure {
    checkAndMergeMap(
            this.thriftTypes,
            that.thriftTypes,
            "thrift type",
            ThriftType.EQUALITY_CHECK
    );
    checkAndMergeMap(
            this.thriftStructTypes,
            that.thriftStructTypes,
            "thrift struct type",
            ThriftStructType.EQUALITY_CHECK

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Rename one of the conflicting aliases so both can coexist
  2. Make the definitions identical (import the same underlying type/variable)
  3. Drop the redundant definition from one scope before merging

Example fix

// before
scopeA: import A.T as X; scopeB: import B.T as X  // clash
// after
scopeA: import A.T as X; scopeB: import B.T as Y
Defensive patterns

Strategy: validation

Validate before calling

for (String k : mapA.keySet()) if (mapB.containsKey(k) && !equal(mapA.get(k), mapB.get(k))) throw new IllegalStateException("conflicting definition: " + k);

Try / catch

catch (SemanticCheckFailure e) { /* rename one conflicting alias */ }

Prevention

When it happens

Trigger: 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.

Common situations: Merging module scopes that both import 'T' from different sources; combining contexts in a larger composition; refactors that introduce duplicate aliases.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/b8aeec0eaab0e98b. Report an issue: GitHub.