fix(类型): 模块限定注解支持 from-import 重导出解析

现场:Test/ThreadingTest/App/main.vp:184 `lock: vthreading.Lock = vthreading.Lock()` 报「变量类型注解解析失败」。vthreading.Lock 是重导出(includes/vthreading.vp `from lock import Lock`),Lock 真定义在 lock.vp;普通模块的 from-import 重导出不像包 __init__ 那样登记别名 entry(VpiReader._inject_reexport_class_declare 仅对包 __init__ 触发),故按 vthreading sha1 查 Lock 恒落空。

resolve_annotation_type 的 Attribute 模块限定分支此前未做真定义模块校正:先按原 sha1 查(既有命中情形逐字不变),未命中时再经 _class_true_def_sha1(唯一真源,已在 _normalize_type_name 规则 4b 使用)校正后重查一次,无证据时原样返回不改变行为。
This commit is contained in:
TermiNexus committed 2026-10-03 15:44:49 +08:00
1 parent c035a82394
commit e196d6a28a
1 file changed
+19
+19
View File
@@ -3325,6 +3325,25 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase):
if mod_entry_v is not None and mod_entry_v.Ty is not None:
# 裸类名(含 mod.Class 限定名)恒为原型(见上方同口径注释)
return mod_entry_v.Ty
# 未命中 ⇒ 该模块可能只是**重导出**(普通模块的 from-import 重导出
# 不像包 __init__ 那样登记别名 entry,见 VpiReader.
# _inject_reexport_class_declare 仅对包 __init__ 触发)。现场:
# includes/vthreading.vp 的 `from lock import Lock`,调用方写
# `vthreading.Lock`(Test/ThreadingTest/App/main.vp:184)⇒ 按
# vthreading sha1 查不到 Lock。此时校正为该类的**真定义模块**
# SHA1 再查一次(唯一真源 _class_true_def_sha1,与
# _normalize_type_name 规则 4b 同口径;无证据时原样返回 ⇒
# 已命中的既有情形在此路径上逐字不变)。
mod_sha1_td: str = self._class_true_def_sha1(pool, at.attr, mod_sha1_v)
if string.strcmp(mod_sha1_td, mod_sha1_v) != 0:
full_q_td: str = self._concat_sha1_class(pool, mod_sha1_td, at.attr)
if full_q_td is not None:
full_ty_td: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type(full_q_td)
if full_ty_td is not None:
return full_ty_td
mod_entry_td: GenTypes.StructEntry* = self.Gen.StructGen.find_struct_by_module(at.attr, mod_sha1_td)
if mod_entry_td is not None and mod_entry_td.Ty is not None:
return mod_entry_td.Ty
# 模块可解析但类未注册:不裸名回退(防跨库抓错),
# 落到下方枚举/typedef 尝试;struct 缺失由调用侧暴露
# 模块名未登记(未编译/未扫描):同样不裸名回退