Sakura Lang

V1001 duplicate_definition

Two items in the same module and namespace have the same name (design §9).

An error from the resolve phase. sakura explain V1001 prints this explanation offline.

Two items in the same module and namespace have the same name (design §9). Rename or remove one; functions are not overloaded by parameter types.

Wrong:

fn answer() -> Int { 41 }
fn answer() -> Int { 42 }

Fixed:

fn answer() -> Int { 42 }

Wrong program

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

fn answer() -> Int { 41 }

fn answer() -> Int { 42 }

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

{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:9d6f5836165be79a",
  "code": "V1001",
  "severity": "error",
  "phase": "resolve",
  "message": "`answer` is defined more than once in this module",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V1001_duplicate_definition::answer",
  "spans": [
    {
      "uri": "file://$DIR/V1001_duplicate_definition.sakura",
      "content_hash": "sha256:351780f2d565fdefc89bb127a89c101039dd0a5acb8ed277b9c8799cf98ee040",
      "start_byte": 64,
      "end_byte": 70,
      "role": "primary"
    },
    {
      "uri": "file://$DIR/V1001_duplicate_definition.sakura",
      "content_hash": "sha256:351780f2d565fdefc89bb127a89c101039dd0a5acb8ed277b9c8799cf98ee040",
      "start_byte": 37,
      "end_byte": 43,
      "role": "definition",
      "label": "first defined here"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V1001",
  "fixes": []
}

Fixed program

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

fn answer() -> Int { 42 }
Edit on GitHub

On this page