// Closure whose return type is a (non-`#inline`) protocol value — exercises
// the indirect-call path where the result is a boxed protocol.

#import "modules/std.sx";

MyProtocol :: protocol {
    get_value :: () -> s64;
}

MyImpl :: struct { value: s64; }
impl MyProtocol for MyImpl {
    get_value :: (self: *MyImpl) -> s64 { self.value; }
}

make_thing :: () -> MyProtocol {
    MyImpl.{ value = 42 };
}

main :: () -> void {
    // Direct call works:
    v := make_thing();
    out("direct call works\n");

    // Closure call crashes:
    c := closure(make_thing);
    result := c();
    out("closure call works\n");
}
