Development · Evolving reference
Defer & scope cleanup
Cleanup follows the scope.
Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →
Registration
defer registers a call or a brace block for normal scope exit. It does not require a hidden heap-allocated closure.
Block form
defer {
FlushMetrics();
ReleaseScratch();
}This fragment assumes the cleanup operations exist. It illustrates a scope-bound sequence rather than an immediately executed block.
Normal exits
A value-producing block's break Value; is a normal exit and runs applicable deferred cleanup. Deferred work and object cleanup follow their documented reverse registration and lifetime order.
Fatal termination
Panic and fatal traps skip cleanup. Sn's design does not supply exception-style unwinding. Use recoverable result paths when normal cleanup and error reporting are required.
Documentation snapshot: October 24, 2026 About versions ↗