Files
2026-10-17 21:57:03 +08:00

29 lines
756 B
Plaintext

import stdio
import testcheck
# nonlocal test: a nested function mutates an outer local
def make_counter() -> callable[[], int]:
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 rawptr function pointer."""
testcheck.section("Closure call via rawptr")
f: callable[[], int] = make_counter()
v: int = f()
testcheck.check(v == 1, "f() first call = 1", "expect 1")
# testcheck.check(v2 == 2, "f2() first call = 2", "expect 2")
def main() -> int:
testcheck.begin("ClosureCallTest: rawptr function pointer call")
test_closure_call()
return testcheck.end()