Files
sx/examples/generics/0214-generics-ufcs-closure-return-pack.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

27 lines
1003 B
Plaintext

// Generic inference where `$R` comes from a worker closure's RETURN type
// through a variadic `..$args` pack — both the DIRECT spelling
// `mymk(bx, worker, 40, 2)` and the UFCS dot-call `bx.mymk(worker, 40, 2)`
// resolve `$R = i64` identically and build `Wrap($R)` correctly.
// Regression (issue 0151): the UFCS path used to splice the receiver as
// arg 0 without running the direct path's pack/closure-return binding, so
// `$R` stayed `.unresolved` and SIGTRAPped at LLVM emission.
#import "modules/std.sx";
Box :: struct { n: i64; }
Wrap :: struct ($R: Type) { value: R; }
mymk :: ufcs (b: Box, worker: Closure(..$args) -> $R, ..$args) -> Wrap($R) {
f : Wrap($R) = ---;
f.value = worker(..args);
return f;
}
main :: () -> i32 {
bx : Box = .{ n = 1 };
direct := mymk(bx, (a: i64, b: i64) -> i64 => a + b, 40, 2);
ufcs := bx.mymk((a: i64, b: i64) -> i64 => a + b, 40, 2);
print("direct={}\n", direct.value);
print("ufcs={}\n", ufcs.value);
return 0;
}