Files
sx/examples/types/0117-types-block-string-arg.sx
agra 959845bd30 style: migrate arrow-block lambdas () => { .. } to () { .. }
The canonical sx block-body lambda is `(params) { stmts }` (and
`(params) -> Ret { stmts }`); the arrow form `=>` is for EXPRESSION bodies
(`(params) => expr`). The arrow-block hybrid `(params) => { .. }` was being
used in 33 files — convert all of them by dropping the `=>`. The two forms are
exactly equivalent (verified: identical IR and identical runtime values — the
block tail is the value with or without a `-> Ret`), so this is a pure source
cleanup: no `.ir` churn, and the only snapshot change is 0923's diagnostic
COLUMN (a negative narrowing test whose error span shifted by the removed `=> `).

Arrow EXPRESSION bodies (`=> expr`, `=> .{..}`, `=> [..]`) and `=>` inside
comments/strings were left untouched. Migrated across examples/concurrency,
examples/{closures,ffi-objc,generics,optionals,types}, issues/, and the stdlib
(io.sx, sched.sx). Suite 855/0.
2026-06-28 16:39:51 +03:00

29 lines
1.0 KiB
Plaintext

// Generic `Into(Block)` impl with a `string`-typed arg in the
// closure signature. The block trampoline declares the param with
// abi(.c); without the abi-collapse fix, sx `string` got
// silently collapsed to `ptr` (the libc `char *` heuristic) and
// the caller's 16-byte `{ptr, len}` value mismatched the
// trampoline's 8-byte `ptr` slot. Result: segfault inside the
// trampoline's first read.
//
// The fix lives in `abiCoerceParamTypeEx`: the `string`/`slice` →
// `ptr` collapse only applies to `is_extern` extern decls (libc
// interop). sx-internal `abi(.c)` keeps the full slice
// shape, which lands as `[2 x i64]` at the LLVM signature site
// and matches the caller's two-register pass on AArch64.
#import "modules/std.sx";
#import "modules/ffi/objc_block.sx";
g_s: string = "";
main :: () -> i32 {
cl := (s: string) { g_s = s; };
b : Block = xx cl;
invoke_fn : (*Block, string) -> void abi(.c) = xx b.invoke;
invoke_fn(@b, "hello");
if g_s.len == 0 { print("FAIL: empty\n"); return 1; }
print("got: <{}>\n", g_s);
0
}