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
1.1 KiB
Plaintext
32 lines
1.1 KiB
Plaintext
// E6BR-4 (param-impl ARG, own-wins) — a parameterised-impl PROTOCOL TYPE-ARG under
|
|
// a wrapper (`impl Tagged(*Box) for Holder`) is resolved through the same
|
|
// source-aware registration helper (`resolveRegistrationSigTypeInSource` with the
|
|
// `.param_impl_arg` purpose), pinned to the impl's defining module (main). The arg
|
|
// `*Box` flows through `resolveCompound` → `resolveNominalLeaf` and selects main's
|
|
// OWN `Box { m }` rather than the flat-imported `dep.sx` `Box { a }`, so the impl
|
|
// registers and `Holder.tag` is callable. (The `param_impl_map` key is name-based,
|
|
// so own-wins registration and any later lookup agree by construction; this cell
|
|
// locks that the wrapped arg routes through the engine, not the no-author leaf.)
|
|
|
|
#import "modules/std.sx";
|
|
#import "0828-protocols-param-impl-arg-wrapped-own-wins/dep.sx";
|
|
|
|
Box :: struct { m: i32; }
|
|
Holder :: struct { n: i32; }
|
|
|
|
Tagged :: protocol(T: Type) {
|
|
tag :: (self: *Self) -> i32;
|
|
}
|
|
|
|
impl Tagged(*Box) for Holder {
|
|
tag :: (self: *Holder) -> i32 {
|
|
self.n
|
|
}
|
|
}
|
|
|
|
main :: () -> i32 {
|
|
h : Holder = .{ n = 7 };
|
|
print("tag={} dep={}\n", h.tag(), dep_box());
|
|
0
|
|
}
|