Files
sx/examples/1165-diagnostics-generic-return-unbound.sx
agra 6b0ebdd92b lang: require explicit receiver in protocol method declarations
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).
2026-06-21 11:02:16 +03:00

25 lines
786 B
Plaintext

// A `$T`-generic RETURN type with no parameter mentioning `$T` is rejected
// at the declaration: the fn isn't a template (type params derive from
// params), and no call site could ever bind the return. All three declare
// surfaces diagnose: a top-level fn, a struct-body method, and a
// (non-parameterised) impl method. Each used to PANIC the compiler at LLVM
// emission via the `.unresolved` tripwire — even when never called.
#import "modules/std.sx";
make :: () -> $T { 0 }
Foo :: struct {
x: i64;
weird :: (self: *Foo) -> $T { 0 }
}
Show2 :: protocol { show2 :: (self: *Self) -> string; }
IntBox :: struct { v: i64; }
impl Show2 for IntBox {
show2 :: (self: *IntBox) -> string { "x" }
leak :: (self: *IntBox) -> $T { 0 }
}
main :: () { print("ok\n"); }