Files
sx/examples/closures/0310-closures-closure-literal-in-defer.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

23 lines
712 B
Plaintext

// Closure literal declared (and used) inside a `defer` body.
//
// Regression (issue 0073): this used to segfault lowering. A lambda inherited
// the enclosing function's `func_defer_base`, so the lambda's `return` re-drained
// the enclosing function's defers — and when the defer body itself declared the
// lambda, that re-lowered the lambda forever (infinite recursion). A lambda now
// opens its own defer window (like every other function-lowering entry).
#import "modules/std.sx";
run :: () {
defer {
cb := (n: i32) -> i32 { return n * 2; };
print("defer closure: {}\n", cb(21)); // 42, at scope exit
}
print("body\n");
}
main :: () -> i32 {
run();
return 0;
}