Files
sx/examples/generics/0208-generics-value-param-type-function.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

33 lines
1.4 KiB
Plaintext

// A type-RETURNING function with a value parameter (`$K: u32`) used as a TYPE
// annotation: `b : Make(N, i64)` where `Make :: ($K, $T) -> Type { return [K]T; }`.
// A named-const value arg (`Make(N, i64)`), a const-expression value arg
// (`Make(M + 1, i64)`), and the literal form (`Make(3, i64)`) all instantiate to
// the SAME type — the array copy `b : Make(3, i64) = a` type-checks only because
// the three spellings name one `[3]i64`.
//
// Regression (issue 0083 / F0.4 attempt 6): the unknown-type checker walked the
// value-param position as a type name ("unknown type 'N'"), and the
// parameterized-type-annotation path never routed to `instantiateTypeFunction`,
// nor did that binder resolve a non-struct/union return shape (`return [K]T`).
// The value arg now folds through the shared const-int evaluator and the type
// function resolves its general return-type expression with bindings active.
#import "modules/std.sx";
N :: 3;
M :: 2;
Make :: ($K: u32, $T: Type) -> Type { return [K]T; }
main :: () {
a : Make(N, i64) = ---; // named-const value param
a[0] = 10; a[1] = 20; a[2] = 30;
print("named: len={} a0={} a2={}\n", a.len, a[0], a[2]);
e : Make(M + 1, i64) = ---; // const-expr value param (M + 1 == 3)
e[0] = 1; e[2] = 9;
print("expr: len={} e2={}\n", e.len, e[2]);
b : Make(3, i64) = a; // same instantiation → array copy type-checks
print("copy: len={} b2={}\n", b.len, b[2]);
}