TS8017
Front-end code SWITCH_CASE
Invalid switch case: a label that is not an integer constant, does not fit the selector, or repeats another; an empty clause with no body below it to share (a trailing one, or one above default:); a body whose end is reachable above a clause with a body, which TypeScript would run on into and WGSL does not (Rule 7.3); or continue in a switch no loop encloses.
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. switch (i32(uv.x * 4.)) { case 0: g = 0.25; break case 0: g = 0.5; break default: g = 1. } return vec4(g, g, g, 1.)}Compiled at build time against the pinned compiler, this program gets:
TS8017 error, line 8: Duplicate switch case 0; each label may appear once.
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. switch (i32(uv.x * 4.)) { case 0: g = 0.25; break case 1: g = 0.5; break default: g = 1. } return vec4(g, g, g, 1.)}The rule this enforces
- Rule 7.3 Test
- An empty
switchcase directly above a case with a body is one clause with several selectors (case 0: case 1:is WGSL’scase 0, 1:); an empty case with no case below it or directly abovedefault:, and an emptydefault:with a case after it, must be refused; a case body must not fall through into the body of a case below it.
See also
Source
Where the compiler raises this code at commit 26de7be8, one line per file:
-
src/compiler/ts/lower/control.ts:751(7 sites)