# E0002

Warning name: `unused_value`

Unused variable.

This variable is unused by any other part of your code, nor marked with `pub`
visibility.

Note that this warning might uncover other bugs in your code. For example, if
there are two variables in your codebase that has similar name, you might just
use the other variable by mistake.

Specifically, if the variable is at the toplevel, and the body of the module
contains side effects, the side effects will not happen.

## Erroneous example

```{literalinclude} /sources/error_codes/0002_error/top.mbt
:language: moonbit
```

## Suggestion

There are multiple ways to fix this warning:

- If the variable is indeed useless, you can remove the definition of the
  variable.
- If this variable is at the toplevel (i.e., not local), and is part of the
  public API of your module, you can add the `pub` keyword to the variable.

  ```{literalinclude} /sources/error_codes/0002_fixed/top.mbt
  :language: moonbit
  :start-after: make public
  :end-before: end make public
  ```

- If you made a typo in the variable name, you can rename the variable to the
  correct name at the use site.
- If your code depends on the side-effect of the variable, you can wrap the
  side-effect in a `fn init` block.

  ```{literalinclude} /sources/error_codes/0002_fixed/top.mbt
  :language: moonbit
  :start-after: side effect solution
  :end-before: end side effect solution
  ```

There are some cases where you might want to keep the variable private and
unused at the same time. In this case, you can call `ignore()` on the variable
to force the use of it.

```{literalinclude} /sources/error_codes/0002_fixed/top.mbt
:language: moonbit
:start-after: ignore unused
:end-before: end ignore unused
```
