Files
sx/examples/closures/0303-closures-closure-returning-protocol.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

29 lines
636 B
Plaintext

// 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 :: (self: *Self) -> i64;
}
MyImpl :: struct { value: i64; }
impl MyProtocol for MyImpl {
get_value :: (self: *MyImpl) -> i64 { 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");
}