Protocol method declarations now declare their receiver explicitly as the first parameter — 'self: *Self' (or 'self: Self') — matching the impl method signature, instead of the old implicit-receiver form where the listed params were only the extra args. That asymmetry repeatedly caused confusion over whether the first param was the receiver or an argument. The parser validates the first param is 'self' typed Self/*Self, then strips it, so all downstream lowering and the dispatch ABI are unchanged (impl blocks and call sites are unaffected). A protocol method missing the receiver is now a parse error. Migrated all 129 protocol method signatures across library + examples (+ one inline-sx test in sema.zig) to the explicit form. Updated specs.md + readme.md. New: examples/0418-protocols-explicit-receiver.sx (feature), examples/1190-diagnostics-protocol-missing-receiver.sx (negative/diagnostic).
32 lines
935 B
Plaintext
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) { }
|
|
}
|