From 8947c5c5eeab7f4c7e619affafbdb397bef2c690 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 20 Aug 2026 00:31:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(gen):=20=E5=A4=9A=E7=BB=A7=E6=89=BF=20this-?= =?UTF-8?q?adjust=20=E5=AF=B9=E6=97=A0=E5=AD=97=E6=AE=B5=E7=88=B6=E7=B1=BB?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E5=AD=97=E8=8A=82=E8=B0=83=E6=95=B4=EF=BC=88?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=20TPC=EF=BC=8CVec2Extra=20=E8=AF=AF=E6=8A=A5?= =?UTF-8?q?=E6=9C=AA=E6=B3=A8=E5=86=8C=E4=BF=AE=E5=A4=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/lib/core/Gen/CallGenCall.vp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/App/lib/core/Gen/CallGenCall.vp b/App/lib/core/Gen/CallGenCall.vp index d867e88..a140424 100644 --- a/App/lib/core/Gen/CallGenCall.vp +++ b/App/lib/core/Gen/CallGenCall.vp @@ -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 未找到",