Sakura Lang

W1002 shadowed_import

A local binding shadows an imported name.

A warning from the resolve phase. sakura explain W1002 prints this explanation offline.

A local binding shadows an imported name. This is allowed but often a mistake; rename one.

Warning:

import std/retry.{retry}
let retry = 3

Fixed:

let max_attempts = 3

Wrong program

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

import std/retry.{retry}

fn attempts() -> Int {
  let retry = 3
  retry
}

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

{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:c9c08b04880cf898",
  "code": "W1002",
  "severity": "warning",
  "phase": "resolve",
  "message": "`retry` shadows an imported name",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::W1002_shadowed_import::attempts",
  "spans": [
    {
      "uri": "file://$DIR/W1002_shadowed_import.sak",
      "content_hash": "sha256:7b139884207f8f349edb814044cd8c6f272074a1ef531789d821f78f2881830d",
      "start_byte": 95,
      "end_byte": 100,
      "role": "primary"
    },
    {
      "uri": "file://$DIR/W1002_shadowed_import.sak",
      "content_hash": "sha256:7b139884207f8f349edb814044cd8c6f272074a1ef531789d821f78f2881830d",
      "start_byte": 58,
      "end_byte": 63,
      "role": "definition",
      "label": "imported here"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/W1002",
  "fixes": []
}

Fixed program

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

fn attempts() -> Int {
  let max_attempts = 3
  max_attempts
}
Edit on GitHub

Last updated

On this page