fix(type): t/c 模块前缀报错补全文件、行列与替代写法

SymbolExtractor 在提取符号前记录 CurrentFile;类型注解拒绝 t./c. 时输出 文件:行:列、完整写法与改写建议。
This commit is contained in:
TermiNexus committed 2026-10-18 14:00:55 +08:00
1 parent c91edd5629
commit a8718aa751
2 files changed
+8 -2

No files matched your search

+1
View File
@@ -23,6 +23,7 @@ class ASTSymbolExtractor:
def extract(self, file_path: str) -> ModuleSymbols:
"""提取文件中的所有符号信息"""
setattr(self._symtab, 'CurrentFile', file_path)
with open(file_path, 'r', encoding='utf-8') as f:
code: str = f.read()
tree: ast.Module = ast.parse(code, file_path)
+7 -2
View File
@@ -963,9 +963,14 @@ class TypeAnnotationResolver:
return CTypeInfo()
if isinstance(Current, ast.Name) and Current.id in ("t", "c"):
FullName: str = f'{Current.id}.{TypeName}'
Line: int = getattr(Node, 'lineno', 0) or 0
Col: int = (getattr(Node, 'col_offset', 0) or 0) + 1
File: str = getattr(SymbolTable, 'CurrentFile', '') or ''
Where: str = f'{File}:{Line}:{Col}' if File else f'第 {Line} 行第 {Col} 列'
raise TypeError(
f"[TPC] 类型注解不再接受 \"{Current.id}.\" 模块前缀;"
f"请直接写内建类型名(如 CPtr、CInt、CArray)。")
f"[TPC] 类型注解不支持模块前缀 \"{FullName}\"({Where})。"
f"请改写为 \"{TypeName}\";指针写 CPtr[T] / rawptr[T]。")
# 解析 import 别名: 如 import vpsdk.window as window -> window -> vpsdk.window
if ModulePath:
resolved: bool = False