Files
sx/examples/diagnostics/1164-diagnostics-inline-for-pack-rejections.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

32 lines
935 B
Plaintext

// `inline for` pack rejections: (1) a pack-element capture exposes only the
// constraint protocol's interface (same rule as `xs[i]`, example 0530);
// (2) a pack element cannot be captured by reference (`(*x)` — an element is
// an AST-substituted call arg, no storage); (3) a trailing pack shorter than
// the driving iterable; (4) a non-pack, non-range iterable.
#import "modules/std.sx";
Show :: protocol { show :: (self: *Self) -> string; }
IntBox :: struct { v: i64; }
impl Show for IntBox { show :: (self: *IntBox) -> string { int_to_string(self.v) } }
leak :: (..xs: Show) {
inline for xs (x) {
print("{}\n", x.v);
}
}
borrow :: (..xs: Show) {
inline for xs (*x) { }
}
short :: (..xs: Show) {
inline for 0..5, xs (i, x) { }
}
main :: () {
leak(IntBox.{ v = 5 });
borrow(IntBox.{ v = 5 });
short(IntBox.{ v = 1 }, IntBox.{ v = 2 });
arr := .[1, 2, 3];
inline for arr (x) { }
}