Files
sx/examples/types/0135-types-self-streaming-nonreserved.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

31 lines
1.1 KiB
Plaintext

// A `*self`-mutating streaming pattern with NON-reserved binding names
// (`hasher`, `ctx`) compiles and accumulates state correctly through BOTH
// call styles — explicit address-of `update(@h, ...)` and autoref
// `h.update(...)` — across multiple mutating calls. Proves the
// `.identifier`-only address-of paths in lowering are correct as-is, with no
// type-shaped-name special-case (companion to the issue-0076 rejection of
// type-named identifiers).
#import "modules/std.sx";
Hasher :: struct { total: i64 = 0; count: i64 = 0; }
update :: ufcs (self: *Hasher, n: i64) {
self.total += n;
self.count += 1;
}
main :: () -> i32 {
hasher := Hasher.{ total = 0, count = 0 };
update(@hasher, 10); // explicit address-of receiver
hasher.update(20); // autoref receiver
update(@hasher, 30);
hasher.update(40);
print("hasher total={} count={}\n", hasher.total, hasher.count);
ctx := Hasher.{ total = 100, count = 0 };
ctx.update(5);
update(@ctx, 7);
print("ctx total={} count={}\n", ctx.total, ctx.count);
return 0;
}