fix(ctor): REnum 变体构造识别取错限定名,导致构造物化豁免失效

_ctor_call_agg_ty 从被调方沿属性链一路走到链根裸名,三段式
llvmlite.LLVMType.Struct(...) 于是被判成限定名 'llvmlite'(非 REnum 类)⇒
返回 None ⇒ ClassGenDef.vp:128 的 *existing.Ty = LLVMType.Struct(...) 被
「指针 → 非基本类型值」禁令拦下。改为取「变体名左边那一段」:两段式取裸名
(EnumType.Variant)、三段式取属性名(llvmlite.LLVMType.Struct → LLVMType)。
This commit is contained in:
TermiNexus committed 2026-10-01 21:44:55 +08:00
1 parent 2f6db41b11
commit be14fa5f94
1 file changed
+15 -10
+15 -10
View File
@@ -705,16 +705,21 @@ novirtual class ExprGenBase:
# 覆盖 `*槽 = <boxed 变体>`。否则该写法会被「指针 → 非基本类型值」禁令拦下
# (现场 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 - 两个聚合类型是否为「同一非基本类型」(构造物化豁免的类型匹配)