fix(gen): 多继承 this-adjust 对无字段父类跳过字节调整(对齐 TPC,Vec2Extra 误报未注册修复)

This commit is contained in:
TermiNexus committed 2026-08-20 00:31:33 +08:00
1 parent e770fef0f7
commit 8947c5c5ee
1 file changed
+13 -5
+13 -5
View File
@@ -963,6 +963,10 @@ class CallGenCall(CallGenBase.CallGenBase):
if first_parent_th is not None and string.strcmp(first_parent_th, mc_anc) == 0:
is_first_parent_th = 1
anc_entry_th: HandlesStruct.StructEntry | t.CPtr = HandlesStruct.find_struct(mc_anc)
# 无字段父类(FieldCount==0,如多继承中的纯方法类 Vec2Extra):
# 继承方法体按"定义类字段"读 self,定义类无字段则方法体不读
# self 布局 → this 无需字节调整,原样传入即可(对齐 TPC
# _adjust_this_for_inherited_method:anc_members 为空直接返回 ObjVal)。
if anc_entry_th is not None and anc_entry_th.FieldCount > 0:
anc_first_name_th: str = None
afi_th: int = 0
@@ -1017,12 +1021,16 @@ class CallGenCall(CallGenBase.CallGenBase):
f"this-adjust 子类结构体未注册: 方法'{method_name}'定义类'{mc_anc}',"
f"接收类'{class_name}'的 struct 未找到",
"InternalCompilerError")
elif is_first_parent_th == 0:
HandlesType.fatal_error(
cl,
f"this-adjust 首字段缺失: 方法'{method_name}'定义类'{mc_anc}'无非 vtable 字段",
"InternalCompilerError")
else:
# 父类仅 __vtable__ 字段(无字段 CVTable 类):方法体不读
# 布局字段,无需调整(对齐 TPC:first_field_name None → ObjVal)
pass
elif anc_entry_th is not None and anc_entry_th.FieldCount == 0:
# 无字段父类:this 无需字节调整(见上方注释)
pass
elif is_first_parent_th == 0:
# 父类 struct 未注册:fail-fast,绝不静默用未调整的 obj_ptr
# 当 self(否则方法按自身布局读字段读到垃圾)
HandlesType.fatal_error(
cl,
f"this-adjust 父类结构体未注册: 方法'{method_name}'定义类'{mc_anc}'的 struct 未找到",