// 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;
}
