From 1f4b231134db6c9485573e843a64f354c500701e Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 13 Aug 2026 07:51:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(stmt):=20=E8=BF=98=E5=8E=9F=20translat?= =?UTF-8?q?e=5Fwith=20=E7=9B=B4=E6=8E=A5=E5=B1=9E=E6=80=A7=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=EF=BC=88TPC=20=E8=81=94=E5=90=88=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8E=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TPC 6a67203 修复了联合类型转换 (X | t.CPtr)(arg) 后属性访问被丢弃的编译损坏, 9f7333b 引入的中间变量 workaround(call_ce/nm_cfn/ovn)不再需要, 还原为直接 ((ast.Call | t.CPtr)(ce)).func 等写法。 --- App/lib/core/Gen/StmtGenMixin.vp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/App/lib/core/Gen/StmtGenMixin.vp b/App/lib/core/Gen/StmtGenMixin.vp index 4325fb2..e8085db 100644 --- a/App/lib/core/Gen/StmtGenMixin.vp +++ b/App/lib/core/Gen/StmtGenMixin.vp @@ -261,10 +261,7 @@ class StmtGenMixin: cls_name: str = None ce: ast.AST | t.CPtr = item.context_expr if ce.kind() == ast.ASTKind.Call: - # 注意:联合类型转换后必须经中间变量再取属性(直接 - # ((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 + cfn: ast.AST | t.CPtr = ((ast.Call | t.CPtr)(ce)).func if cfn is not None: if cfn.kind() == ast.ASTKind.Attribute: ca: ast.Attribute | t.CPtr = (ast.Attribute | t.CPtr)(cfn) @@ -279,8 +276,7 @@ class StmtGenMixin: if cls_name is None: cls_name = ca.attr elif cfn.kind() == ast.ASTKind.Name: - nm_cfn: ast.Name | t.CPtr = (ast.Name | t.CPtr)(cfn) - cls_name = nm_cfn.id + cls_name = ((ast.Name | t.CPtr)(cfn)).id # context 对象存入 __with_ctx(方法调用解析 self 用) ctx_alloca: llvmlite.Value | t.CPtr = llvmlite.build_alloca( builder, ctx_val.Ty) @@ -299,9 +295,7 @@ class StmtGenMixin: if item.optional_vars is not None: ov: ast.AST | t.CPtr = item.optional_vars if ov.kind() == ast.ASTKind.Name: - # 联合类型转换后经中间变量再取属性(同 L264 注释,防 TPC 编译损坏) - ovn: ast.Name | t.CPtr = (ast.Name | t.CPtr)(ov) - asname: str = ovn.id + asname: str = ((ast.Name | t.CPtr)(ov)).id if asname is not None: bind_val: llvmlite.Value | t.CPtr = enter_val if bind_val is None: