TS8017
On this page

TS8017

Front-end code SWITCH_CASE

An 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 body whose end is reachable above a clause with a body, which TypeScript runs on into and WGSL does not (Rule 7.3); or a continue in a switch that no loop encloses.

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

example.shade.ts
"use typeshade"
@fragment
export function main(uv: location<0, 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.

example.shade.ts
"use typeshade"
@fragment
export function main(uv: location<0, 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 switch case directly above a case with a body is one clause with several selectors (case 0: case 1: is WGSL’s case 0, 1:); an empty case with no case below it or directly above default:, and an empty default: 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 af54ddad5, one line per file:

Edit this page Report a problem