Files
sx/examples/errors/1026-errors-failable-main.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

30 lines
1.2 KiB
Plaintext

// Failable `-> !` main entry-point wrapper (ERR step E4.2). A pure-failable
// main that lets an error reach the function boundary exits 1 and prints the
// unhandled-error header (with the tag name, via the always-linked tag-name
// table) plus the return trace to stderr — instead of the old behavior of
// returning the raw tag id as the exit code with no diagnostic. A successful
// run (no escaping error) exits 0.
//
// Note: the header + trace go to stderr. The test runner merges stderr+stdout,
// so the snapshot shows them interleaved with the `print` (stdout) lines.
// Frame locations are placeholders until DWARF (ERR E3.0); count + ordering +
// the tag name are already meaningful. Expected exit code: 1.
#import "modules/std.sx";
ParseErr :: error { Empty, BadDigit };
inner :: (n: i32) -> (i32, !ParseErr) {
if n == 0 { raise error.Empty; } // pushes a frame
if n < 0 { raise error.BadDigit; }
return n * 2;
}
main :: () -> !ParseErr {
v := try inner(5); // succeeds → v = 10
print("v = {}\n", v);
w := try inner(0); // raises Empty → propagates to main
print("w = {}\n", w); // never reached
return;
}