Skip to content

Grouped case labels in a switch ​

Status: accepted · Date: 2026-12-05

Issue #391 showed that Tolean refused a switch like this one as fallthrough:

ts
switch (s.kind) {
  case 'circle':
  case 'square':
    return true;
  case 'point':
    return false;
}

A case with no statements is not fallthrough. CaseBlockEvaluation (ECMA-262 §14.12.4) runs on from the matched clause until a clause completes abruptly. An empty clause completes normally, so control reaches the next clause's body. TypeScript's noFallthroughCasesInSwitch accepts this shape for the same reason.

The decision ​

clauseGroup skips the empty clauses after a label and returns the body that the labels share. translateClauses and translateStateClauses translate each label with that body, so the output has one match arm for each label. The interpreter needs no change, because execFrom already runs on through an empty clause. The proof uses one new lemma, execFrom_group, which says that running from the label equals running the shared body and then the clauses after it.

A clause with statements that runs into the next one is still refused.

We considered copying the shared body into each empty clause before translation. We rejected it, because the copy is not equivalent when the body can end without a break: the copy would then run into the original.

Map borrows ​

The borrow check reads a switch as an if chain (Stmt.switchChain). A group becomes one if for each label, each with the shared body. The translator still refuses an if chain that changes a map and tests three or more members, so the corpus tests a group in a borrow only where the chain drops it: a group that ends the switch and does nothing.

This page is docs/decisions/2026-12-05-switch-grouped-cases.md at commit 5f1d031.