Files
sx/examples/protocols/0413-protocols-parameterized-protocol-value.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

23 lines
886 B
Plaintext

// Phase 4.2 — parameterized protocol as a runtime VALUE type. `VL(i64)` is a
// 16-byte protocol value {ctx, vtable} (a plain protocol was already, but a
// parameterized one used to resolve to a 0-field stub). A conforming struct
// `xx`-erases into it, and method dispatch uses the bound type-arg
// (`get -> T` becomes `get -> i64` for `VL(i64)`).
#import "modules/std.sx";
VL :: protocol(T: Type) { get :: (self: *Self) -> T; }
IntCell :: struct { v: i64; }
StrCell :: struct { s: string; }
impl VL(i64) for IntCell { get :: (self: *IntCell) -> i64 => self.v; }
impl VL(string) for StrCell { get :: (self: *StrCell) -> string => self.s; }
main :: () -> i32 {
a : VL(i64) = xx IntCell.{ v = 42 };
print("a.get={}\n", a.get()); // 42 (T = i64)
b : VL(string) = xx StrCell.{ s = "hi" };
print("b.get={}\n", b.get()); // hi (T = string)
0
}