diff --git a/App/lib/core/Gen/Type/TypeGenResolve.vp b/App/lib/core/Gen/Type/TypeGenResolve.vp index 988826d..bd5a307 100644 --- a/App/lib/core/Gen/Type/TypeGenResolve.vp +++ b/App/lib/core/Gen/Type/TypeGenResolve.vp @@ -2765,8 +2765,10 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase): sp_sha_buf2[sp_len2 - 1] = '\0' sp_entry2: GenTypes.StructEntry* = self.Gen.StructGen.find_struct_by_module(nm.id + sp_len2, sp_sha_buf2) if sp_entry2 is not None and sp_entry2.Ty is not None: - if sp_entry2.HasNew != 0: - return llvmlite.Ptr(pool, sp_entry2.Ty) + # 裸类名恒为**原型**(struct 本身,值/布局语义),不再看 HasNew: + # 堆对象引用必须显式写 `T*` / `T | t.CPtr` / `rawptr[T]` + # (用户 2026-10-01 定;TPC 侧注解链路本无 __new__ 升指针逻辑, + # 天然同口径,故 TPC 无需同步改)。 return sp_entry2.Ty # 兜底:按完整前缀名直接查(部分注册键即全名) sp_full2: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type(nm.id) @@ -2803,14 +2805,14 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase): if trans is not None and trans.ModuleSha1 is not None: own_entry: GenTypes.StructEntry* = self.Gen.StructGen.find_struct_by_module(nm.id, trans.ModuleSha1) if own_entry is not None and own_entry.Ty is not None: - # 有 __new__ 的类(堆对象)注解 → Ptr(struct)(引用语义,对齐 TPC)。 - # 否则无 __new__ 的类(栈对象,如 Point)保持 struct 值语义: - # 构造返回栈 alloca 指针,赋给 struct 值变量时 coerce load 拷贝。 - # 背景:d: dict = dict(bd) 的 dict 是堆对象(__new__ 分配), - # 裸名注解按值解析会让 sub: dict = sub_p 把 i8* 当 struct 解引用 - # 崩溃(DictTest Test 13)。 - if own_entry.HasNew != 0: - return llvmlite.Ptr(pool, own_entry.Ty) + # 裸类名恒为**原型**(struct 本身):注解说的是"类型/布局", + # 不再按 HasNew 自动升成 Ptr(struct)。堆对象引用一律显式写 + # `T*` / `T | t.CPtr` / `rawptr[T]`(用户 2026-10-01 定; + # TPC 侧注解链路本无 __new__ 升指针逻辑,天然同口径, + # 故 TPC 无需同步改)。旧行为(有 __new__ ⇒ Ptr(struct))是 + # 为兼容 `d: dict = dict(bd)` 这类"裸名 + 构造"写法而设, + # 代价是同一类型出现"裸名=指针 / 联合=再加一层"的分裂 + # (现场 includes/json/__init__.vp:90 CastError)。 return own_entry.Ty # from-import 归属查找:注解里的裸名(或 import 别名)经 from_imports 定位到 # 定义模块,再按 (name, sha1) 精确取类——这是 stub 注入场景的正解:此刻 @@ -2829,18 +2831,12 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase): if fi_sha1 is not None: fi_entry: GenTypes.StructEntry* = self.Gen.StructGen.find_struct_by_module(nm.id, fi_sha1) if fi_entry is not None and fi_entry.Ty is not None: - if fi_entry.HasNew != 0: - return llvmlite.Ptr(pool, fi_entry.Ty) + # 裸类名恒为原型(见上方同口径注释) return fi_entry.Ty if self.Gen.StructGen.is_struct_visible(nm.id) != 0: struct_ty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type(nm.id) if struct_ty is not None: - nm_entry_s: GenTypes.StructEntry* = self.Gen.StructGen.find_struct_by_type(struct_ty) - nm_has_new_s: int = 0 - if nm_entry_s is not None: - nm_has_new_s = nm_entry_s.HasNew - if nm_has_new_s != 0: - return llvmlite.Ptr(pool, struct_ty) + # 裸类名恒为原型(见上方同口径注释):不再因 HasNew 升成 Ptr return struct_ty # 枚举类(t.CEnum)裸名注解 → 底层整数类型 # 如 fat32_types.vp 内部 `res: FRESULT = ...`(FRESULT 是枚举非结构体) @@ -3039,8 +3035,7 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase): return full_ty_v mod_entry_v: GenTypes.StructEntry* = self.Gen.StructGen.find_struct_by_module(at.attr, mod_sha1_v) if mod_entry_v is not None and mod_entry_v.Ty is not None: - if mod_entry_v.HasNew != 0: - return llvmlite.Ptr(pool, mod_entry_v.Ty) + # 裸类名(含 mod.Class 限定名)恒为原型(见上方同口径注释) return mod_entry_v.Ty # 模块可解析但类未注册:不裸名回退(防跨库抓错), # 落到下方枚举/typedef 尝试;struct 缺失由调用侧暴露