---
title: "Rule 7.3: Expressions and statements in TypeShade"
description: "Rule 7.3 of the TypeShade language design, in Expressions and statements."
url: https://typeshade.dev/reference/rules/7-3/
language: en
---

# 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](https://github.com/typeshade/typeshade/issues/168) changed this rule, which refused every empty case).

## Derives from

[Switch Statement](https://gpuweb.github.io/gpuweb/wgsl/#switch-statement).

## 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](https://github.com/typeshade/typeshade/issues/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:

- [`src/compiler/ts/fallthrough.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/fallthrough.ts#L1)
- [`src/compiler/ts/operators-statements.test.ts:156`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/operators-statements.test.ts#L156)
- [`src/compiler/ts/switch-array.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/switch-array.test.ts#L1)

## Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

- [§52 Operators, switch and statements: what WGSL spells, and what it does not](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#52-operators-switch-and-statements-what-wgsl-spells-and-what-it-does-not)

## Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

**[`TS8017`](https://typeshade.dev/reference/errors/ts8017/) `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.

## See also

- [Rule 7.2](https://typeshade.dev/reference/rules/7-2/) Test
- [Rule 7.4](https://typeshade.dev/reference/rules/7-4/) Test
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

- [`docs/language-design.md:682`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L682) (the design document)
- [`reqs/rules/RULE-0703.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0703.md) (its traceability item)
