# E0009

Warning name: `struct_never_constructed`

The struct is never constructed.

## Erroneous example

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

## Suggestion

The `pub` visibility modifier only allows other packages to access the struct,
by dot-syntax (`a.value`), or by pattern matching. Therefore, if you expect
other packages to be able to construct the struct, you should use the `pub(all)`
visibility modifier.

```{literalinclude} /sources/error_codes/0009_fixed/top.mbt
:language: moonbit
:start-after: use pub(all)
:end-before: end use pub(all)
```

However, if you do not want other packages to construct the struct, this might
be due to incompleteness or bugs in your code. There are some common cases:

- You planned to use smart constructors or factory functions to construct the
  struct, but you forgot or have not implemented them.
- You intended to keep the struct private to control its instantiation but may
  have forgotten to provide a way to do so within its own package.

In these cases, you should consider providing a way to construct the struct
within its own package.

```{literalinclude} /sources/error_codes/0009_fixed/top.mbt
:language: moonbit
:start-after: smart constructor
:end-before: end smart constructor
```
