Files
sx/examples/errors/1027-errors-failable-main-value.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
855 B
Plaintext

// Value-carrying failable main `-> (int, !)` (ERR step E4.2). The entry-point
// wrapper extracts the `{value, error}` tuple main returns: on success it exits
// with the integer value (truncated to u8, like a plain integer main); on an
// escaping error it prints the header + trace to stderr and exits 1 (the same
// reporter as the pure `-> !` form — see 244). This run takes the success path.
// Expected exit code: 64 (the returned value).
#import "modules/std.sx";
ParseErr :: error { Empty, BadDigit };
inner :: (n: i32) -> (i32, !ParseErr) {
if n == 0 { raise error.Empty; }
if n < 0 { raise error.BadDigit; }
return n * 2;
}
main :: () -> (i32, !ParseErr) {
v := try inner(32); // succeeds → v = 64
print("v = {}\n", v);
return v; // success → exit code 64
}