diff --git a/lib/core/Handles/HandlesImports.py b/lib/core/Handles/HandlesImports.py index 944089a..fd14f7e 100644 --- a/lib/core/Handles/HandlesImports.py +++ b/lib/core/Handles/HandlesImports.py @@ -1221,6 +1221,8 @@ class ImportHandle(BaseHandle): # `_TryLoadClassMembersFromPyi ↔ _EmitExternalClassDeclLlvm ↔ _TryLoadStructFromStub` # 环)。此处 fail-fast 上抛(保留原始栈),暴露上游根因而非掩盖。 raise + except TypeError: + raise except Exception as e: # NoneType 异常是数据缺失的正常兜底,静默不 WARN(干扰太多) if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)): @@ -1366,6 +1368,12 @@ class ImportHandle(BaseHandle): TypeInfo = CTypeInfo.FromNode(Node.annotation, self.Trans.SymbolTable) if TypeInfo: var_type = Gen._ctype_to_llvm(TypeInfo) + if isinstance(var_type, ir.VoidType): + raise TypeError( + f"[TPC] 全局变量 '{VarName}' 的类型注解 " + f"'{getattr(Node.annotation, 'id', type(Node.annotation).__name__)}' " + f"解析为 void(第 {getattr(Node, 'lineno', 0)} 行);" + f"请检查该类型是否已定义或声明顺序是否正确。") IsPtr = TypeInfo.IsPtr if isinstance(var_type, ir.IdentifiedStructType) and (var_type.elements is None or len(var_type.elements) == 0): var_type = ir.IntType(32)