# E0006

Warning name: `unused_constructor`

Variant is never read, never constructed, or both.

- If a variant is never read, it means it is defined but never destructed in a
  pattern matching expression (`match`, `let`, `guard let`, loop function,
  etc.).
- If a variant `A` is never constructed, it means there is no `A(...)`.
- If a variant is unused, it means it is never constructed and never read.

## Erroneous example

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

## Suggestion

- If some variants are never read, while others are read, this means that you
  have use wildcard pattern (`_`) in your code. You can expand the wildcard
  pattern to include the unused variants.

  ```{literalinclude} /sources/error_codes/0006_fixed/top.mbt
  :language: moonbit
  :start-after: expand wildcard
  :end-before: end expand wildcard
  ```

- If all variants are never read, and you need to read these variants outside of
  current package, you can add `pub` keyword to the enum definition. Notice this
  will make the implementation of the variant visible to the users of the
  package.

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

- If you need to construct the "never constructed" variant outside of the
  current package, you can add `pub(all)` keyword to the variant.

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

- If some variants are indeed useless, you can remove the unused variants.

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