Attempts 1–4 fixed the array-dimension paths but the same length-0 fabrication class survived on every other site that resolves a compile-time integer. Unify them all on the single shared `program_index.evalConstIntExpr` so they cannot diverge: - All three Vector lane resolvers (resolveTypeCallWithBindings, resolveParameterizedWithBindings, resolveArrayLiteralType) and both generic value-param binders (instantiateGenericStruct, instantiateTypeFunction) hand-rolled an `else => 0` switch. A module-const lane `Vector(N, f32)` fabricated a 0-lane `<0 x float>` (LLVM "huge alignment" abort); a value-param `Vec(N, f32)` fabricated a 0 binding / wrong mangled name. They now fold through the shared evaluator and emit a clean diagnostic + `.unresolved` on a non-const operand (resolveVectorLane / resolveValueParamArg) — never 0. - evalComptimeInt (inline-for bounds) delegated to the shared evaluator, so `inline for 0..M` / `0..(M+1)` fold like array dims. The `<pack>.len` leaf moved into the shared folder via a new `ctx.lookupPackLen`. - The unknown-type semantic checker no longer walks a value-param position (`Vector(N, …)` / `Vec(N, …)`) as a type name (was reporting "unknown type 'N'"). - The parameterized-type-arg parser and the function-body lookahead (hasFnBodyAfterArrow) accept a const-EXPRESSION in a value position, so `Vector(M + 1, f32)` and `[M + 1]T` parse as a return type too (the latter a pre-existing array-dim sibling that the same heuristic broke). Regressions: examples/1501 (named-const + const-expr lane, direct + alias, 3/4-lane reads), 1502 (runtime lane clean-halts, exit 1, no LLVM crash), 0207 (Vec(N)/Vec(M+1) == Vec(3) instantiation), 0610 (inline-for const bounds). Shared-evaluator unit test extended with the pack-len arm. zig build && zig build test && bash tests/run_examples.sh: 395 passed, 0 failed.
24 lines
901 B
Plaintext
24 lines
901 B
Plaintext
// `inline for 0..K` with a named-const or constant-foldable bound unrolls at
|
|
// compile time, just like a literal bound.
|
|
//
|
|
// Regression (issue 0083): the inline-for bound folder (`evalComptimeInt`) only
|
|
// handled literals, comptime cursors, and `<pack>.len`, so `inline for 0..M`
|
|
// (M a module const) and `inline for 0..(M + 1)` (a const expression) both
|
|
// failed with "range end is not a compile-time integer". `evalComptimeInt` now
|
|
// delegates to the single shared const-int evaluator
|
|
// (`program_index.evalConstIntExpr`), so the inline-for bound and an array
|
|
// dimension fold the same shapes to the same value.
|
|
#import "modules/std.sx";
|
|
|
|
M :: 3;
|
|
|
|
main :: () {
|
|
s := 0;
|
|
inline for 0..M: (i) { s += i; }
|
|
print("sum 0..M = {}\n", s); // 0 + 1 + 2 = 3
|
|
|
|
t := 0;
|
|
inline for 0..(M + 1): (i) { t += i; }
|
|
print("sum 0..(M+1) = {}\n", t); // 0 + 1 + 2 + 3 = 6
|
|
}
|