From 9f7333b0f23f4deae760d261b212837a4e241646 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 13 Aug 2026 07:37:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(stmt):=20translate=5Fwith=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=AE=BF=E9=97=AE=E6=94=B9=E7=94=A8=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E5=8F=98=E9=87=8F=EF=BC=8C=E8=A7=84=E9=81=BF=20TPC=20=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E6=8D=9F=E5=9D=8F=E8=87=B4=20asname=20=E6=9C=AA?= =?UTF-8?q?=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TransPyC 编译 translate_with 时,联合类型转换后直接取属性(如 ((ast.Name|CPtr)(ov)).id / ((ast.Call|CPtr)(ce)).func)的属性访问 (GEP+load)被编译器丢弃——编译产物 75904e6cbc83036b.text.ll 显示 store %asname 0 次、load 3 次,asname 恒 null → pool 从未绑定到 SymTab → body 内 pool.alloc 方法调用检测 lookup_var 失败 → 误报 "跨模块调用 'pool.alloc' 找不到模块 SHA1"。同理 cfn 恒 null 导致 cls_name(AnnotClassName)也设置不上。改为先转换到中间变量再取属性 (代码库已验证编译正常的 cmn 模式),修复 3 处(L264/L279/L298)。 --- App/lib/core/Gen/StmtGenMixin.vp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/App/lib/core/Gen/StmtGenMixin.vp b/App/lib/core/Gen/StmtGenMixin.vp index e8085db..4325fb2 100644 --- a/App/lib/core/Gen/StmtGenMixin.vp +++ b/App/lib/core/Gen/StmtGenMixin.vp @@ -261,7 +261,10 @@ class StmtGenMixin: cls_name: str = None ce: ast.AST | t.CPtr = item.context_expr if ce.kind() == ast.ASTKind.Call: - cfn: ast.AST | t.CPtr = ((ast.Call | t.CPtr)(ce)).func + # 注意:联合类型转换后必须经中间变量再取属性(直接 + # ((ast.Call|CPtr)(ce)).func 会被 TPC 编译损坏丢弃属性访问) + call_ce: ast.Call | t.CPtr = (ast.Call | t.CPtr)(ce) + cfn: ast.AST | t.CPtr = call_ce.func if cfn is not None: if cfn.kind() == ast.ASTKind.Attribute: ca: ast.Attribute | t.CPtr = (ast.Attribute | t.CPtr)(cfn) @@ -276,7 +279,8 @@ class StmtGenMixin: if cls_name is None: cls_name = ca.attr elif cfn.kind() == ast.ASTKind.Name: - cls_name = ((ast.Name | t.CPtr)(cfn)).id + nm_cfn: ast.Name | t.CPtr = (ast.Name | t.CPtr)(cfn) + cls_name = nm_cfn.id # context 对象存入 __with_ctx(方法调用解析 self 用) ctx_alloca: llvmlite.Value | t.CPtr = llvmlite.build_alloca( builder, ctx_val.Ty) @@ -295,7 +299,9 @@ class StmtGenMixin: if item.optional_vars is not None: ov: ast.AST | t.CPtr = item.optional_vars if ov.kind() == ast.ASTKind.Name: - asname: str = ((ast.Name | t.CPtr)(ov)).id + # 联合类型转换后经中间变量再取属性(同 L264 注释,防 TPC 编译损坏) + ovn: ast.Name | t.CPtr = (ast.Name | t.CPtr)(ov) + asname: str = ovn.id if asname is not None: bind_val: llvmlite.Value | t.CPtr = enter_val if bind_val is None: