TS8017
프런트엔드 코드 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.
레지스트리 설명과 컴파일러 메시지는 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
예제
"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.)}빌드할 때 고정된 컴파일러로 이 프로그램을 컴파일하면 다음 진단이 나옵니다.
TS8017 error, 8행: Duplicate switch case 0; each label may appear once.
고치는 법
같은 프로그램을 고친 모습입니다. 진단 없이 컴파일됩니다.
"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.)}이 코드가 적용하는 규칙
- 규칙 7.3 테스트
- 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.
함께 보기
소스
커밋 c66579bf에서 컴파일러가 이 코드를 내는 곳입니다. 파일마다 한 줄씩 적었습니다.