Files
sx/examples/192-pack-non-conform.sx
agra fc4d239fdd lang 2.4: enforce protocol-pack conformance per position
Each argument bound to a `..xs: P` pack must conform to P — previously the
constraint was decorative (any type was accepted). `lowerPackFnCall` now
captures the pack param's constraint protocol and checks each pack arg via a
new `packArgConformsTo`, which accepts: a plain-protocol impl
(`protocol_thunk_map`), any parameterised impl `P(<args>) for T` (scan of
`param_impl_map` for a `P\x00…\x00mangle(T)` key — the per-element type-args
are inferred from the impl, not written out), or an arg already erased to P's
own protocol struct. Non-conformers get a per-position error pointing at the
argument. Only enforced for a known protocol constraint.

Regression: examples/192-pack-non-conform.sx (a struct lacking `impl Show` in a
`..xs: Show` pack → diagnostic, exit 1).
2026-05-29 18:01:48 +03:00

25 lines
686 B
Plaintext

// Feature 1 — a pack argument that doesn't conform to the constraint protocol
// is a per-position error. `Naked` has no `impl Show`, so passing it to a
// `..xs: Show` pack is rejected (pointing at the offending argument).
#import "modules/std.sx";
Show :: protocol(T: Type) {
get :: (self: *Self) -> T;
}
IntBox :: struct { v: s64; }
impl Show(s64) for IntBox { get :: (self: *IntBox) -> s64 => self.v; }
Naked :: struct { x: s64; } // intentionally NOT `impl Show`
howmany :: (..xs: Show) -> s64 {
return xs.len;
}
main :: () -> s32 {
a := IntBox.{ v = 1 };
n := Naked.{ x = 2 };
print("{}\n", howmany(a, n)); // `n` does not conform to Show
0;
}