Rule 7.3
Chapter 7, Expressions and statements 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.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
WGSL’s switch has no fall-through, but a clause may carry several selectors, which is what stacked empty cases mean in TypeScript; the three refused shapes have no clause the compiler can join them to (surface §52; #168 changed this rule, which refused every empty case).
Derives from
How it is verified
Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.
Where the rule says the compiler enforces it:
src/compiler/ts/switch-array.test.ts (shares one body between two selectors, on both targets); TS8017 SWITCH_CASE for the three refused shapes (switch case 1 has no body: …, switch case 1 sits above "default:" with no body of its own. …, "default:" has no body of its own and a clause follows it. …); TS8017 SWITCH_CASE at the label of a case or default: whose end is reachable and below which a clause has a body (switch case 0 falls through into the next case: …), by TypeScript’s own reachability (src/compiler/ts/fallthrough.ts), in src/compiler/ts/operators-statements.test.ts (a case body does not fall through, #202). A case that runs on only into empty clauses at the end of the switch runs nothing more in TypeScript either, and is not refused.
The files that verify it at commit af54ddad5, each at the first line that names the rule:
Explained in
The sections of the surface document that explain this rule, at commit af54ddad5:
Error codes that enforce it
The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:
-
TS8017SWITCH_CASE - An invalid
switchcase: 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 acontinuein a switch that no loop encloses.
See also
- Rule 7.2 Test
- Rule 7.4 Test
- Design rules
- Error codes
Source
The rule at commit af54ddad5:
docs/language-design.md:682(the design document)reqs/rules/RULE-0703.md(its traceability item)