diff --git a/App/lib/core/Gen/Type/TypeGenResolve.vp b/App/lib/core/Gen/Type/TypeGenResolve.vp index 9c8382f..988826d 100644 --- a/App/lib/core/Gen/Type/TypeGenResolve.vp +++ b/App/lib/core/Gen/Type/TypeGenResolve.vp @@ -3261,6 +3261,28 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase): # 回退 Ptr(i8) 由 AnnotClassName 恢复 + 多遍注册收敛 # 处理,禁止 fail-fast(误杀合法前向引用)。 return llvmlite.Ptr(pool, llvmlite.Int8(pool)) + # struct 引用语义吸收(本文件 :3219-3221 早已写明、此前未实现的 + # 那条规则):other_ty 若已是「指向已注册 struct 的指针」,说明 + # 该侧裸类名已按**引用语义**解析过(有 __new__ 的堆类,Name/ + # Attribute 分支直接给 Ptr(struct),见 :2806-2813、:3040-3044) + # ⇒ `| t.CPtr` 不再追加一层,否则多一层指针。 + # 三种写法必须同型(用户 2026-09-30 定:统一为 T*): + # T* ≡ rawptr[T] ≡ t.CPtr[T] ≡ T | t.CPtr + # 现场:includes/json/__init__.vp:90 `return cur` + # `def __getitem__(...) -> 'JsonValue' | t.CPtr`(**引号字符串** + # 注解,左边是 Constant 不是 Name —— 绕过了上面 :3176 那段 + # "Name 必须已注册 struct 否则丢弃"的守卫,于是带着 Ptr(struct) + # 走到这里再包一层 ⇒ JsonValue**),而 `cur: JsonValue*` 是 + # JsonValue* ⇒ CastError「指针层数不同(源 1 级 → 目标 2 级)」。 + # 之所以只在引号写法暴露:裸名写法会在 :3222-3239 被判定 + # td_res_is_ptr=1 → other_ty 置 None → 走 :3254 回退取 struct 再包 + # 一层,恰好抵消;引号写法绕过了那条路径。 + match other_ty: + case llvmlite.LLVMType.Ptr(pointee_ab): + if self.Gen.StructGen.find_struct_by_type(pointee_ab) is not None: + return other_ty + case _: + pass return llvmlite.Ptr(pool, other_ty) # t.CPtr[...] 下标指针标记(普通 _is_cptr_marker 不识别 Subscript):