switch repeats a case value, so the later branch is dead

ID

dart.correctness.no_duplicate_case_values

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

low

Resource

Control Flow

Language

Dart

Description

Reports a switch statement in which two case clauses carry the same value.

Rationale

A switch dispatches to the first clause whose value matches, so the second occurrence can never be reached and its body is dead code. The duplicate is almost always a copy-paste of a clause whose value was meant to be changed, which means the value the author intended to handle is not handled at all and silently falls through to the default clause, or out of the switch entirely. Nothing at runtime distinguishes that from a deliberate fallback.

The following code illustrates the pattern detected by this rule:

class Router {
  String byCode(int code) {
    // FLAGGED: switch repeats a case value, so the later branch is dead
    switch (code) {
      case 200:
        return 'ok';
      case 404:
        return 'missing';
      case 200:
        return 'still ok';
      default:
        return 'other';
    }
  }
}

Remediation

Decide which value the second clause was meant to match and give it that value. If the two clauses really share one body, list them together as consecutive labels on a single clause rather than repeating the body; if the clause is genuinely redundant, delete it.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved