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 一致)。
This commit is contained in:
TermiNexus committed 2026-10-08 20:42:14 +08:00
1 parent 07fbb4d0a2
commit 1724874967
8 files changed
+71 -15

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
from stdint import *
# =============================================================================
# 负向工程(**应当编译失败**,对照工程:NewLifetimeTest)
#
# 协程体(async)里的 `new heap slife` 必须被拒:AsyncGenMixin 的状态机会把 body 拆成多个
# state 块并多次转译,编译器无法确定释放点 → CallGenCtor._translate_new_expr 在此 fail-fast
# (LifetimeError,提示改用 `new heap hlife` 或把分配挪进普通函数)。
#
# 说明见 Debugger/ownership-and-new.md §4.2 的「async 的收口」。
# `new stack`(帧内 alloca,本来就无需释放)与 `new … hlife`(自行管理)不受这条约束影响。
# =============================================================================
novirtual class Point:
x: int
y: int
async def Bad() -> int:
p: Point* = new heap slife Point(1, 2) # ← 必须被拒
return p.x
export def main() -> int:
return 0
+29
View File
@@ -0,0 +1,29 @@
{
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
"name": "NewLifetimeAsyncTest",
"version": "1.0.0",
"source_dir": "./App",
"build_dir": "./.tpv_build",
"compiler": {
"cmd": "llc",
"flags": ["-filetype=obj", "-relocation-model=pic"]
},
"linker": {
"cmd": "clang++",
"flags": ["-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32"],
"output": "NewLifetimeAsyncTest.exe"
},
"includes": [
"../../includes"
],
"target": {
"triple": "x86_64-pc-windows-gnu",
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
},
"options": {
"slice_level": 3,
"sha1_slice_level": 1,
"target": "llvm",
"strict_mode": true
}
}