31 lines
1.1 KiB
Plaintext
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: s64 = 0; count: s64 = 0; }
|
|
|
|
update :: ufcs (self: *Hasher, n: s64) {
|
|
self.total += n;
|
|
self.count += 1;
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
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;
|
|
}
|