// E6b — own-wins for an ERROR-SET name in a CLOSURE-LITERAL return annotation
// (`closure(() -> !IoErr { … })`). `main` flat-imports `dep.sx` (which authors
// `IoErr { Net }`) AND authors its OWN `IoErr { Disk }`. The closure literal's
// `-> !IoErr` channel must resolve to `main`'s OWN author (own-wins), so the
// `raise error.Disk` inside the closure body validates against main's `{ Disk }`;
// meanwhile `dep_err` keeps dep's DISTINCT `IoErr { Net }`.
//
// Fail-before (attempt-1): `lowerLambda` resolved the explicit `lam.return_type`
// through the STATELESS `type_bridge.resolveAstType`, so the closure's `!IoErr`
// channel bound the global last-wins author (dep's `{ Net }`); `error.Disk` was
// then "not in error set 'IoErr'" and the program exited 1.
//
// Pass-after: the lambda return annotation routes through the source-aware
// `resolveTypeWithBindings` (same path as the regular function-return channel),
// main's own `IoErr` wins, `error.Disk` validates, exit 0.

#import "modules/std.sx";
#import "0813-modules-same-name-error-set-lambda-own-wins/dep.sx";

IoErr :: error { Disk }

main :: () -> i32 {
    fail_own := closure(() -> !IoErr { raise error.Disk; });
    fail_own() catch (e) {
        if e == error.Disk { print("own=Disk\n"); }
    };
    d := dep_err();
    print("dep={}\n", d);
    return 0;
}
