// The cleanup-absorption check (ERR step E1.7) is TRANSITIVE: a bare,
// un-absorbed failable call is rejected no matter how deeply it is nested
// inside a `defer` / `onfail` body's control flow — through `if` (both
// branches), nested blocks, and loops. 1049 covers the direct-body case; this
// pins the recursive arms of `checkCleanupNode` (`.if_expr`, `.block`,
// `.while_expr`) before A5.2 extracts the pass into its own module.
//
// Three bare failables, three rejections; the program never runs (exit 1).

#import "modules/std.sx";

E :: error { Bad }

failing :: () -> !E { raise error.Bad; }

work :: (n: i32) -> !E {
    defer {
        if n > 0 {
            failing();              // REJECTED: nested in the `if` then-branch
        } else {
            { failing(); }          // REJECTED: nested block in the else-branch
        }
    }
    onfail {
        while n > 0 {
            failing();              // REJECTED: nested in the `while` body
        }
    }
    if n < 0 { raise error.Bad; }
    return;
}

main :: () -> i32 {
    a := work(-1);
    return 0;
}
