From 337be883d34f3e5c11098709391a7f4b4b305a91 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Fri, 9 Oct 2026 20:57:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(nll):=20Attribute=20=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E5=8F=AA=E9=80=92=E5=BD=92=20.value=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D"=E6=8B=BF=E4=B8=8D=E5=88=B0=E5=AD=90?= =?UTF-8?q?=E6=A0=91=3D=E7=AE=97=E6=8F=90=E5=8F=8A"=E6=8A=8A=20stdio.print?= =?UTF-8?q?f(...)=20=E8=AF=AF=E5=88=A4=E6=88=90=E4=B8=8D=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现场:EscapeTest 的 h = new heap S() 永不降级(g(l,h) 照旧报逃逸)。根因是 _NllMentions 对 Attribute 落进保守分支(children 不含 value 时返回"提及")→ _NllExprUnsafe 把 stdio.printf("%s", h.q) 判为不安全 → 整个 NLL 判据返回 0。属性名是静态字符串,变量只可能在基对象里,显式递归 .value 即可。 --- App/lib/core/Gen/StructGenMixin.vp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/App/lib/core/Gen/StructGenMixin.vp b/App/lib/core/Gen/StructGenMixin.vp index 74225d1..1dec661 100644 --- a/App/lib/core/Gen/StructGenMixin.vp +++ b/App/lib/core/Gen/StructGenMixin.vp @@ -730,6 +730,13 @@ novirtual class StructGenMixin: if nm.id is not None and self._NllInSet(al, nm.id) != 0: return 1 return 0 if k == ast.ASTKind.Constant: return 0 + # 属性访问:变量只可能出现在基对象里(`.attr` 是静态字符串),必须显式只递归 .value。 + # 否则若该节点的 children 不含 value,就会落进下面的"拿不到子树 = 算提及"分支 → + # 把 `stdio.printf(...)` 之类误判成提及/不安全,整条 NLL 判据被否掉(现场:该误判 + # 使 `h = new heap S()` 永不降级,g(l, h) 照旧报逃逸)。 + if k == ast.ASTKind.Attribute: + at: ast.Attribute* = ast.Attribute*(node) + return self._NllMentions(at.value, al) ch: list[ast.AST*]* = node.children if ch is None: return 1 n: sizet = len(ch)