Files
TermiNexus aed57de44c test(lifetime): 新增 willFree 正/负向工程并注册到回归脚本
NewLifetimeWillFreeTest(二次 free)、NewLifetimeUseAfterFreeTest(释放后使用)为负向;NewLifetimeWillFreeOkTest 验证合法用法与重赋值清除失效态。同步更新 SequentialRegressionTest / regression_test / run_lifetime_negative_tests 与 README。
2026-10-08 21:28:55 +08:00

22 lines
897 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from stdint import *
import stdlib
# =============================================================================
# 负向工程(**应当编译失败**,对照工程:NewLifetimeWillFreeOkTest)
#
# P2 willFree 标注驱动:`includes/stdlib.vp` 的 free 带 `@life(willFree(p))`,
# 语义 = "该实参所指对象在本调用返回后失效"。编译器读到被调者的该标注后,把对应
# **实参变量槽**标为"已失效",其后再读/传/再 free → LifetimeError(fail-fast)。
#
# 本工程:第二次 free(p) 必须在编译期被拒(p 在第一次 free 后已失效)。
# 期望报错:LifetimeError。
# =============================================================================
export def main() -> int:
p: rawptr = stdlib.malloc(8)
stdlib.free(p)
stdlib.free(p) # ← 必须被拒:p 已失效(二次释放)
return 0