Files
sx/examples/closures/0308-closures-arrow-inferred-return.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

25 lines
1.1 KiB
Plaintext

// Regression (issue 0059): a function with NO explicit return type infers it
// from the body, which references the function's own parameters. The inference
// must see those params — before the fix they weren't in scope during
// return-type resolution, so the inferred type came out `.unresolved` and tripped
// the LLVM-emission guard ("unresolved type reached LLVM emission"). Whether it
// slipped through used to depend on a same-named binding lingering from earlier
// lowering. Covers the arrow (`=>`) and inferred-via-`return` forms, at top level
// and as locals.
#import "modules/std.sx";
dbl :: (x: i32) => x * 2; // top-level arrow, inferred return
inc :: (x: i32) { return x + 1; } // top-level block, inferred via `return`
main :: () {
print("{}\n", dbl(7)); // 14
print("{}\n", inc(41)); // 42
tripl :: (x: i32) => x * 3; // local arrow, inferred return
print("{}\n", tripl(4)); // 12
half :: (x: f32) => x / 2.0; // inferred float return
print("{}\n", half(9.0)); // 4.500000
}