# M0028 shadowed variable (/docs/diagnostics/codes/m0028)

<Diagnostic code="M0028" />

Assignments go to the inner one, which is then unused, and the outer one keeps its old value. This often loses an error.

## The mistake and the fix [#the-mistake-and-the-fix]

<div className="code-pair">

```go title="The mistake"
var err error
if ok {
	data, err := load() // a new err
	use(data)
}
return err // always nil
```

```go title="Fixed"
var err error
if ok {
	var data []byte // [!code highlight]
	data, err = load() // [!code highlight]
	use(data)
}
return err // [!code highlight]
```

</div>

## The fix [#the-fix]

Declare the other variables first and assign with =.

See also [all error codes](/docs/diagnostics/codes) and [marmot explain](/docs/commands/explain).