fix(type): 联合类型前向自我引用误杀恢复回退

json 等类的字段 'JsonValue | t.CPtr' 引用自身类,类体处理中尚未注册(前向自我引用)是合法场景,由 Phase A-pre 多遍注册 + AnnotClassName 恢复处理。恢复类名未注册时回退 Ptr(i8),禁止 fail-fast 误杀。
This commit is contained in:
TermiNexus committed 2026-08-13 02:32:22 +08:00
1 parent 03df4f1a20
commit 1b80283634
1 file changed
+6 -6
+6 -6
View File
@@ -1910,12 +1910,12 @@ class TypeGenMixin:
other_cls_ty: llvmlite.LLVMType | t.CPtr = HandlesStruct.get_struct_type(other_cls_nm)
if other_cls_ty is not None:
return llvmlite.Ptr(pool, other_cls_ty)
# fail-fast:CPtr 标记下 other 侧类型完全无法解析,
# 不再静默退化为 i8*,暴露上游类型错误根因。
# (t.CVoid | t.CPtr → i8* 的合法语义分支在 other_is_cvoid 处已提前返回)
HandlesType.fatal_error(
node, f"联合类型 '{HandlesType.annotation_to_str(node)}' 中类型无法解析", "NameError")
return llvmlite.Ptr(pool, llvmlite.Int8(pool)) # 不可达(fatal_error 已退出)
# 类名未注册:可能是前向自我引用(如 json 的
# 'JsonValue' | t.CPtr 字段引用自身类,类体处理中
# 尚未注册)或 Phase A-pre 依赖类延迟到下一遍注册。
# 回退 Ptr(i8) 由 AnnotClassName 恢复 + 多遍注册收敛
# 处理,禁止 fail-fast(误杀合法前向引用)。
return llvmlite.Ptr(pool, llvmlite.Int8(pool))
return llvmlite.Ptr(pool, other_ty)
# 无 CPtr 标记:返回第一个非 None(装饰器标记如 CExport/CExtern 被忽略)