From f1530aac916419bc944e6de01fcfdf9f3a599f0d Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 13 Aug 2026 07:12:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(stmt):=20with=20=E7=9A=84=20asname=20?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E7=B1=BB=E5=90=8D=E5=B8=A6=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=89=8D=E7=BC=80=EF=BC=8C=E4=BF=AE=E5=A4=8D=E8=B7=A8=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=96=B9=E6=B3=95=E8=B0=83=E7=94=A8=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit translate_with 提取 context 类名时只取裸类名(MemPool),跨模块调用 (如 pool.alloc)的 AnnotClassName 回退需模块限定名(memhub.MemPool) 才能按模块查 SHA1,裸名导致方法调用判定失败、落入"跨模块调用找不到 模块 SHA1"误报。改为与 AnnAssign 的 extract_class_name_from_annotation 一致:Attribute func(memhub.MemPool)生成 "memhub.MemPool" 注解类名。 --- App/lib/core/Gen/StmtGenMixin.vp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/App/lib/core/Gen/StmtGenMixin.vp b/App/lib/core/Gen/StmtGenMixin.vp index 38593eb..e8085db 100644 --- a/App/lib/core/Gen/StmtGenMixin.vp +++ b/App/lib/core/Gen/StmtGenMixin.vp @@ -255,14 +255,26 @@ class StmtGenMixin: trans._funcs, trans._func_count, trans) if ctx_val is None: continue - # 提取类名:Call(func=Attribute("memhub"."MemPool") / Name("MemPool")) + # 提取类名(注解类名,Attribute 时带模块前缀,如 "memhub.MemPool"—— + # 与 AnnAssign 的 extract_class_name_from_annotation 一致,跨模块 + # 方法调用靠 AnnotClassName 回退按模块名查 SHA1) 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 if cfn is not None: if cfn.kind() == ast.ASTKind.Attribute: - cls_name = ((ast.Attribute | t.CPtr)(cfn)).attr + ca: ast.Attribute | t.CPtr = (ast.Attribute | t.CPtr)(cfn) + if ca.value is not None and ca.value.kind() == ast.ASTKind.Name: + cmn: ast.Name | t.CPtr = (ast.Name | t.CPtr)(ca.value) + if cmn.id is not None: + ml2: t.CSizeT = string.strlen(cmn.id) + string.strlen(ca.attr) + 2 + mbuf: str = pool.alloc(ml2) + if mbuf is not None: + viperlib.snprintf(mbuf, ml2, "%s.%s", cmn.id, ca.attr) + cls_name = mbuf + if cls_name is None: + cls_name = ca.attr elif cfn.kind() == ast.ASTKind.Name: cls_name = ((ast.Name | t.CPtr)(cfn)).id # context 对象存入 __with_ctx(方法调用解析 self 用)