fix(lifetime): 目标为值类型即判 LIFE_VALUE(不再要求源非指针) - class 局部变量内部为指针槽,修 stars 误报

This commit is contained in:
TermiNexus committed 2026-10-15 21:59:39 +08:00
1 parent cbadc356f9
commit d1dd6de070
1 file changed
+6 -3
+6 -3
View File
@@ -1082,9 +1082,12 @@ novirtual class AssignGenMixin:
# 此前只覆盖「裸数组名」,于是 `col: V3 = V3(...)` 后 `return col` 落到 get_var_life # 此前只覆盖「裸数组名」,于是 `col: V3 = V3(...)` 后 `return col` 落到 get_var_life
# 读回本帧 LIFE_FRAME,被 check_return_frame_decl 误报 LifetimeError。 # 读回本帧 LIFE_FRAME,被 check_return_frame_decl 误报 LifetimeError。
# 只排除"变量值本身或目标位置是地址"的情形:`p: V3*` 的 `return p` 仍判帧生命期。 # 只排除"变量值本身或目标位置是地址"的情形:`p: V3*` 的 `return p` 仍判帧生命期。
elif (inner is not None and target_ty is not None # 目标位置是**值类型**(函数按值返回、赋值给值类型槽)时,读出的值会整块拷贝到目标
and self.Gen.ExprGenBase.is_ptr_type(inner) == 0 # ⇒ LIFE_VALUE。这里**不要求变量本身也非指针**:class 的局部变量内部是"指针槽"
and self.Gen.ExprGenBase.is_ptr_type(target_ty) == 0): # (诊断实证:stars 的 col 为 iptr=1,而 clmp 的形参 a 为 iptr=0,两者表示不同),
# 但返回类型是聚合值(rvkind=4)时会做值拷贝,交出的仍是拷贝而非栈地址。
# 反例仍拦:`p: V3*` 的 `return p`(target 是指针,tptr=1)不进入本分支,仍判帧生命期。
elif target_ty is not None and self.Gen.ExprGenBase.is_ptr_type(target_ty) == 0:
res = GenTypes.LIFE_VALUE res = GenTypes.LIFE_VALUE
hit = 4 hit = 4
else: else: