修正了种子编译器的错误

This commit is contained in:
2026-07-22 21:55:36 +08:00
parent 135aa05485
commit ca7c2120b8
1185 changed files with 12056 additions and 2673 deletions

View File

@@ -0,0 +1,39 @@
import t
import stdio
import testcheck
# ============================================================
# ClosureCallTest - t.CPtr 函数指针调用最小化复现
#
# closure_test.py 中 f: t.CPtr = make_counter() 后调用 f() 报错:
# Undefined function: 'f'
# 根因f 是 t.CPtr(i8*)line 322 检查 pointee 是 FunctionType 失败
# ============================================================
# nonlocal 关键字测试:嵌套函数修改外层局部变量
def make_counter() -> t.CPtr:
count: int = 0
# 内部函数(闭包)捕获 count
def counter() -> int:
nonlocal count
count = count + 1
return count
return counter
def test_closure_call():
"""验证 t.CPtr 函数指针调用"""
testcheck.section("Closure call via t.CPtr")
f: t.CPtr = make_counter()
v: int = f()
testcheck.check(v == 1, "f() first call = 1", "expect 1")
def main() -> t.CInt:
testcheck.begin("ClosureCallTest: t.CPtr function pointer call")
test_closure_call()
return testcheck.end()