{"record":{"id":"e312999ac8b0cd38","repo":"xai-org/x-algorithm","slug":"there-is-no-type-context","errorCode":null,"errorMessage":"There is no type context","messagePattern":"There is no type context","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/CompilerContext.java","lineNumber":284,"sourceCode":"  void defineVariable(\n      String variableName,\n      ASTNode astNode) throws SemanticCheckFailure {\n    defineVariable(variableName, astNode.getReturnType(), astNode);\n  }\n\n  Variable getVariable(String variableText) throws SemanticCheckFailure {\n    for (CompilerScope scope : scopeList) {\n      if (scope.isVariableDefined(variableText)) {\n        Parameter parameter = scope.getVariable(variableText);\n        return new Variable(variableText, parameter);\n      }\n    }\n    throw new SemanticCheckFailure(String.format(\"variable %s not defined\", variableText));\n  }\n\n  TypeContext getTypeContext() throws SemanticCheckFailure {\n    if (scopeList.isEmpty()) {\n      throw new SemanticCheckFailure(\"There is no type context\");\n    }\n\n    return scopeList.getFirst();\n  }\n\n  void defineType(ThriftType thriftType, String alias) throws SemanticCheckFailure {\n    if (scopeList.size() <= 1) {\n      throw new SemanticCheckFailure(\n          String.format(\"type cannot defined in root scope: %s\", alias));\n    }\n\n    CompilerScope scope = currentScope();\n    scope.defineType(thriftType, alias);\n  }\n\n  void defineType(ThriftStructType scroogeType, String alias) throws SemanticCheckFailure {\n    if (scopeList.size() <= 1) {\n      throw new SemanticCheckFailure(","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/CompilerContext.java#L266-L302","documentation":"getTypeContext returns the innermost scope as the type context and throws when the scope list is empty. Type lookups (aliases, thrift types) are impossible without an active scope.","triggerScenarios":"Calling type resolution helpers (type, paramTp) before any scope is pushed, e.g. during a custom compilation phase that runs outside compile() or after scopes were cleared.","commonSituations":"Custom CompilerUnit hooks resolving types at registration time instead of compile time; misuse of the internal API; error-path scope unwinding.","solutions":["Resolve types inside the compile-time scope (within createASTNodeTree/compile)","Push a scope with addScope() before type resolution","Move type alias definitions/imports into a scoped construct so lookups happen with an active scope"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (SemanticCheckFailure e) { /* internal: ensure type resolution occurs within compile() with a pushed scope */ }","preventionTips":["Resolve types only during scoped compilation","Push scopes explicitly in custom phases"],"tags":["botmaker","scope","type-context","internal-invariant"],"backgroundTag":"empty-scope-stack","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}