# `layout.promotion_required`

Declaration is used beyond the file that holds it.

Area 1, [Project layout and modules](/docs/project-layout-and-modules.md); not declinable; the next step is usually the agent's.

```jadpo
use planning/actions { SnoozeDays }

action postpone_all(days: SnoozeDays) -> Unit {}
```

```jadpo
type SnoozeDays = Int {
    min: 1
    max: 30
}

action snooze_todo(days: SnoozeDays) -> Unit {}
```

```text
error: `SnoozeDays` is used beyond this file
 --> domains/planning/actions/snooze_todo.jadpo:1:6
  |
1 | type SnoozeDays = Int {
  |      ^^^^^^^^^^ used by another file
  reason: A type used by one file lives in it; once another file uses it, it moves to a file of its own in `domains/planning/types/`. `domains/planning/actions/postpone_all.jadpo` uses it too.
  next: Move `SnoozeDays` to `domains/planning/types/snooze_days.jadpo`, or run `jadpo fmt --layout`, which moves it and updates the imports (agent)
  rule: layout.promotion_required
  help: https://jadpo.dev/docs/errors/layout.promotion_required

check failed: 1 error, 3 files
```

Moving to the right folder is not enough: a second declaration in a file
moves to a file of its own once another file uses it, so every name a `use`
line brings in is `<folder>/<name>.jadpo`. The edit makes the move, and
`jadpo fmt --layout` makes it and updates the imports:


```jadpo
type DiscountCode = Text {
    max_length: 12
}

type Basket = Object {
    code: DiscountCode
}
```

```text
error: `DiscountCode` is used beyond this file
 --> domains/sales/types/basket.jadpo:1:6
  |
1 | type DiscountCode = Text {
  |      ^^^^^^^^^^^^ used by another file
  reason: A declaration another file uses has a file of its own named after it, so its `use` line says where it is; `DiscountCode` is in `basket.jadpo`, named after another declaration, and moves to `domains/sales/types/`. `domains/sales/actions/apply_code.jadpo` uses it too.
  next: Move `DiscountCode` to `domains/sales/types/discount_code.jadpo`, or run `jadpo fmt --layout`, which moves it and updates the imports (agent)
  rule: layout.promotion_required
  help: https://jadpo.dev/docs/errors/layout.promotion_required

check failed: 1 error, 3 files
```

```jadpo
use sales/types { Basket, DiscountCode }

action apply_code(basket: Basket, code: DiscountCode) -> Unit {}
```

A move whose new file would carry another declaration's name too is left
for you: `ListBooks`'s own file would be `list_books.jadpo`, action
`list_books`'s name, which is `naming.folded_collision`. The error says to
rename the type first, and `jadpo fmt --layout` refuses the move until then:


```jadpo
use shop/actions { ListBooks }

action browse_books(filter: ListBooks) -> Unit {}
```

```jadpo
type ListBooks = Input {
    page_size: PageSize {
        default: 25
    }
}

action list_books(filter: ListBooks) -> Unit {}
```

```text
error: `ListBooks` is used beyond this file
 --> domains/shop/actions/list_books.jadpo:1:6
  |
1 | type ListBooks = Input {
  |      ^^^^^^^^^ used by another file
  reason: A type used by one file lives in it; once another file uses it, it moves to a file of its own in `domains/shop/types/`. `domains/shop/actions/browse_books.jadpo` uses it too. Its own file would be `list_books.jadpo`, the file name of `list_books`, an action in `domains/shop/actions/list_books.jadpo`.
  next: Rename `ListBooks` first, so its file name differs from `list_books`'s, then move it to `domains/shop/types/` (agent)
  rule: layout.promotion_required
  help: https://jadpo.dev/docs/errors/layout.promotion_required

check failed: 1 error, 3 files
```
