# W1002 shadowed_import

URL: /docs/errors/W1002
Markdown: /docs/errors/W1002.md

> 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:

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

Fixed:

```sakura
let max_attempts = 3
```

## Wrong program [#wrong-program]

[`compiler/tests/ui/W1002_shadowed_import.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/W1002_shadowed_import.sakura), which the compiler's ui suite runs through `sakura check`:

```sakura
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):

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:e62db61b2fa70d49",
  "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.sakura",
      "content_hash": "sha256:85bf3bd33fd7034ff2f082a235afd9dfe7293700fc964b6860c8251319e073f4",
      "start_byte": 89,
      "end_byte": 94,
      "role": "primary"
    },
    {
      "uri": "file://$DIR/W1002_shadowed_import.sakura",
      "content_hash": "sha256:85bf3bd33fd7034ff2f082a235afd9dfe7293700fc964b6860c8251319e073f4",
      "start_byte": 52,
      "end_byte": 57,
      "role": "definition",
      "label": "imported here"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/W1002",
  "fixes": []
}
```

## Fixed program [#fixed-program]

[`compiler/tests/ui/W1002_shadowed_import.fixed.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/W1002_shadowed_import.fixed.sakura), which `sakura check` accepts with no diagnostics:

```sakura
import std/retry.{retry}

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