Files
Viper_RegressionTesting/ClosureCallTest/App/main.vp
T
TermiNexus ee6461be46 chore(comments): Test 仓注释英文化(R11)
把 81 个 .vp 文件的中文 # 注释与三引号文档串改写为简洁英文,每个连续注释块 <=2 行;运行时中文字符串字面量(testcheck.begin/print 等用户可见消息)保持原样。骨架比对 HEAD 与工作区 112 文件漂移 0,全量 77/77 顺序回归通过。
2026-10-05 22:43:38 +08:00

35 lines
825 B
Plaintext

import t
import stdio
import testcheck
# ClosureCallTest - minimal repro: call through a t.CPtr function pointer
# f is t.CPtr (i8*); the compiler must treat its pointee as callable.
# nonlocal test: a nested function mutates an outer local
def make_counter() -> t.CPtr:
count: int = 0
# Inner closure captures count
def counter() -> int:
nonlocal count
count = count + 1
return count
return counter
def test_closure_call():
"""Verify calling a t.CPtr function pointer."""
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() -> int:
testcheck.begin("ClosureCallTest: t.CPtr function pointer call")
test_closure_call()
return testcheck.end()