TS8008
Front-end code LOOP_INDUCTION
A for loop whose counter is not one let of type i32 or u32, or whose update is not a constant step.
The registry has no documentation comment for this constant, so the line above is written by this site from the messages the compiler raises it with.
The registry text and every compiler message on these pages are the compiler's own English.
Example
"use typeshade"
@fragmentexport function main(@location(0) uv: vec2): vec4 { let g = 0. for (let t: f32 = 0.; t < 1.; t += 0.25) { g += t * uv.x } return vec4(g, g, g, 1.)}Compiled at build time against the pinned compiler, this program gets:
TS8008 error, line 6: for induction must be i32 or u32, got f32.
How to fix it
The same program, corrected. It compiles with no diagnostic.
"use typeshade"
@fragmentexport function main(@location(0) uv: vec2): vec4 { let g = 0. for (let i = 0; i < 4; i++) { g += f32(i) * 0.25 * uv.x } return vec4(g, g, g, 1.)}The rule this enforces
- Rule 7.5 Test
- A
forloop must be counted: ani32oru32induction variable, a constant step, and an exit that compares the induction variable to a bound; the start and the bound may be runtime values, the loop body must not write the bound, and the step must move the variable toward the bound.
See also
Source
Where the compiler raises this code at commit 26de7be8, one line per file:
-
src/compiler/ts/loop-bound.ts:298(3 sites) -
src/compiler/ts/lower/control.ts:113(8 sites)