specs.md lumped `inline for` / `for` range bounds in with counts (array dimension, Vector lane count, generic value-param count) under the count negative-rejection rule. A range bound is a range ENDPOINT, not a count: negative endpoints are valid and an empty/inverted range runs zero iterations. The compiler already implements this correctly (Agra ruling: spec-text bug, no code change). - specs.md: counts and range bounds are now described separately. Counts reject negatives; bounds accept any compile-time integer (negatives valid, integral floats fold) but still reject a non-integral float because the loop cursor must be an integer. - examples/0612-comptime-inline-for-range-bounds.sx: `inline for -2..1` and `for -2..1` both sum -3; `inline for 0..(-2.0)` runs zero iterations (empty range). Runtime/comptime parity asserted. - examples/1138-diagnostics-inline-for-non-integral-bound.sx: a non-integral float bound `inline for 0..4.5` is a clean diagnostic, exit 1 (must-be-integer still applies to bounds). Count consumers (1132/1133/1134/1135) unchanged and green.
25 lines
992 B
Plaintext
25 lines
992 B
Plaintext
// An `inline for` / `for` range bound is a range ENDPOINT, not a count, so the
|
|
// count negative-rejection rule does NOT apply to it: negative endpoints are
|
|
// valid and an empty/inverted range simply runs zero iterations.
|
|
//
|
|
// Regression (F0.4 attempt 11, Agra ruling): the spec wrongly lumped inline-for
|
|
// bounds with counts (array dim / Vector lane / value-param), which reject
|
|
// negatives. Bounds are exempt — `inline for -2..1` iterates -2,-1,0 and an
|
|
// integral-float empty range `0..(-2.0)` runs zero iterations. Comptime and
|
|
// runtime loops must agree.
|
|
#import "modules/std.sx";
|
|
|
|
main :: () {
|
|
s := 0;
|
|
inline for -2..1: (i) { s += i; }
|
|
print("inline for -2..1 sum = {}\n", s); // -2 + -1 + 0 = -3
|
|
|
|
r := 0;
|
|
for -2..1: (i) { r += i; }
|
|
print("for -2..1 sum = {}\n", r); // -2 + -1 + 0 = -3 (runtime parity)
|
|
|
|
e := 0;
|
|
inline for 0..(-2.0): (i) { e += i; }
|
|
print("inline for 0..(-2.0) sum = {}\n", e); // empty range -> 0 iterations
|
|
}
|