From a91bd8f35bff848a50d6fa315b9c257b46515c5c Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sun, 18 Oct 2026 15:49:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(imports):=20extern=20=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E7=B1=BB=E5=9E=8B=E4=B8=BA=20void=20?= =?UTF-8?q?=E6=97=B6=20fail-fast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GlobalVariable 不接受 void 指针;解析为 void 时输出变量名、注解与行号,并让 TypeError 穿透外层忽略异常的兜底。 --- lib/core/Handles/HandlesImports.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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)