fix(gen): 模块属性访问支持别名解析(import X as Y → Y._attr)

直接写 GenGenerator._g_gen = gen(别名模块属性)此前不可用:
_resolve_module_attribute_global 未解析别名,_lookup_module_sha1
("GenGenerator") 查不到(Sha1Store 用原始模块名)→ 退化裸名 →
全局带 SHA1 前缀后 undefined symbol。

修复:查目标模块 SHA1 前经 from_imports 解析别名(lookup_from_import
返回原始模块名 lib.core.Gen.Generator)。别名属性写与 setter 调用等价
(写同一 @<模块sha1>._g_gen),且更高效(无函数调用/链接依赖)。
This commit is contained in:
TermiNexus committed 2026-08-20 04:37:50 +08:00
1 parent 5f7a87341a
commit 252d15ba9f
1 file changed
+9
+9
View File
@@ -237,6 +237,15 @@ class ExprGenAttr(ExprGenBase.ExprGenBase):
mod_path_w: str = self._attr_module_path_str(pool, at.value)
if mod_path_w is None:
return None
# 别名解析:import lib.core.Gen.Generator as GenGenerator → 查 from_imports
# 得原始模块名。否则 _lookup_module_sha1("GenGenerator") 查不到(Sha1Store
# 用原始模块名)→ 退化裸名 → 全局带 SHA1 前缀后 undefined symbol。
# 别名属性访问(GenGenerator._g_gen = gen)依赖此解析才能命中目标模块定义。
if trans._from_imports is not None:
orig_mw: str = HandlesImports.lookup_from_import(
trans._from_imports, mod_path_w, 0)
if orig_mw is not None:
mod_path_w = orig_mw
# 检查是否是已导入模块
if HandlesImports.is_module_imported(trans._imported_modules, mod_path_w) == 0:
return None