Sakura Lang

V4002 unreachable_arm

A match arm can never be reached because earlier arms already cover every value it matches.

An error from the pattern phase. sakura explain V4002 prints this explanation offline.

A match arm can never be reached because earlier arms already cover every value it matches. Remove it, or move it before the arm that shadows it.

Wrong:

match o { _ => 0, Some(n) => n }

Fixed:

match o { Some(n) => n, _ => 0 }

Wrong program

compiler/tests/ui/V4002_unreachable_arm.sakura, which the compiler's ui suite runs through sakura check:

fn sign(n: Int) -> String {
  match n {
    0 => "zero",
    _ => "nonzero",
    1 => "one",
  }
}

sakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):

{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:96fe8174deffcb7c",
  "code": "V4002",
  "severity": "error",
  "phase": "pattern",
  "message": "this arm is unreachable: earlier arms already match every value it matches",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V4002_unreachable_arm::sign",
  "spans": [
    {
      "uri": "file://$DIR/V4002_unreachable_arm.sakura",
      "content_hash": "sha256:863e370cf52c6eff741e6b056bc563e6a4bcd6add4c015ebadd53620de317889",
      "start_byte": 115,
      "end_byte": 116,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V4002",
  "fixes": []
}

Fixed program

compiler/tests/ui/V4002_unreachable_arm.fixed.sakura, which sakura check accepts with no diagnostics:

fn sign(n: Int) -> String {
  match n {
    0 => "zero",
    1 => "one",
    _ => "other",
  }
}
Edit on GitHub

On this page