Files
Viper_RegressionTesting/NewLifetimeFreeTest/App/main.vp
T
TermiNexus 1724874967 test(lifetime): 新增 NewLifetimeAsyncTest 负向工程;测试项目 main 统一为 export def main() -> int
- NewLifetimeAsyncTest:协程体里的 new heap slife 必须报 LifetimeError(fail-fast 的回归覆盖),已挂进 ESCAPE_PROJECTS / NEGATIVE_PROJECTS / NEGATIVE_PROJECT_NAMES 与 README。

- NewLifetimeTest / NewLifetimeFreeTest 的 main 改为 export def main() -> int,并删掉多余的 t/c 导入(与 FuncTest / FormatStringTest / NewTest 一致)。
2026-10-08 20:42:14 +08:00

27 lines
812 B
Plaintext
Raw 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 w32.win32console
import stdlib
# =============================================================================
# 负向工程(**应当编译失败**,对照工程:NewLifetimeTest)
#
# §4.3 判据 5:`slife` 对象由编译器独占释放 —— 禁止手动 free。
# 理由:出口已经会自动 free 一次,再手动 free 就是 double-free。
# 期望报错:LifetimeError。
# =============================================================================
novirtual class Point:
x: int
y: int
export def main() -> int:
w32.win32console.SetConsoleCP(65001)
w32.win32console.SetConsoleOutputCP(65001)
p: Point* = new heap slife Point(1, 2)
stdlib.free(p) # ← 必须被拒:slife 由编译器在函数出口释放
return 0