From be14fa5f941db781fa7ebff948a6f49adf919710 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 1 Oct 2026 21:44:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(ctor):=20REnum=20=E5=8F=98=E4=BD=93?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E8=AF=86=E5=88=AB=E5=8F=96=E9=94=99=E9=99=90?= =?UTF-8?q?=E5=AE=9A=E5=90=8D=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E7=89=A9=E5=8C=96=E8=B1=81=E5=85=8D=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _ctor_call_agg_ty 从被调方沿属性链一路走到链根裸名,三段式 llvmlite.LLVMType.Struct(...) 于是被判成限定名 'llvmlite'(非 REnum 类)⇒ 返回 None ⇒ ClassGenDef.vp:128 的 *existing.Ty = LLVMType.Struct(...) 被 「指针 → 非基本类型值」禁令拦下。改为取「变体名左边那一段」:两段式取裸名 (EnumType.Variant)、三段式取属性名(llvmlite.LLVMType.Struct → LLVMType)。 --- App/lib/core/Gen/Expr/ExprGenBase.vp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/App/lib/core/Gen/Expr/ExprGenBase.vp b/App/lib/core/Gen/Expr/ExprGenBase.vp index 0de14fc..7e758aa 100644 --- a/App/lib/core/Gen/Expr/ExprGenBase.vp +++ b/App/lib/core/Gen/Expr/ExprGenBase.vp @@ -705,16 +705,21 @@ novirtual class ExprGenBase: # 覆盖 `*槽 = `。否则该写法会被「指针 → 非基本类型值」禁令拦下 # (现场 ClassGenDef.vp:128 `*existing.Ty = llvmlite.LLVMType.Struct(...)`)。 if cl.func.kind() == ast.ASTKind.Attribute: - base_v: ast.AST* = (ast.Attribute*(cl.func)).value - # 取属性链最右的裸名(llvmlite.LLVMType → LLVMType) - while base_v is not None and base_v.kind() == ast.ASTKind.Attribute: - base_v = (ast.Attribute*(base_v)).value - if base_v is not None and base_v.kind() == ast.ASTKind.Name: - base_nm: str = (ast.Name*(base_v)).id - if base_nm is not None and self.Gen.ClassGenEnum._is_renum_class_name(base_nm) != 0: - rn_ent: GenTypes.StructEntry* = self.Gen.StructGen.find_struct(base_nm) - if rn_ent is not None and rn_ent.Ty is not None: - return rn_ent.Ty + # 取「变体名左边那一段」作为枚举类名:被调方形如 `<限定链>.<变体>`, + # EnumType.Variant → 限定段是裸名 EnumType + # llvmlite.LLVMType.Struct → 限定段是属性 LLVMType(**不是**链根 + # llvmlite,早期实现走到链根导致漏判) + qual: ast.AST* = (ast.Attribute*(cl.func)).value + base_nm: str = None + if qual is not None: + if qual.kind() == ast.ASTKind.Attribute: + base_nm = (ast.Attribute*(qual)).attr + elif qual.kind() == ast.ASTKind.Name: + base_nm = (ast.Name*(qual)).id + if base_nm is not None and self.Gen.ClassGenEnum._is_renum_class_name(base_nm) != 0: + rn_ent: GenTypes.StructEntry* = self.Gen.StructGen.find_struct(base_nm) + if rn_ent is not None and rn_ent.Ty is not None: + return rn_ent.Ty return None # ============================================================ # _same_agg_ty - 两个聚合类型是否为「同一非基本类型」(构造物化豁免的类型匹配)