# XO0167: top level declaration inside a block

`fn`, `struct`, `enum`, `interface`, `type`, `use`, `test`, and anything marked `pub` may appear only at the top level of a file. Inside a function, use a closure (`let name = fn(...) { ... }`) instead of a nested function. `const` is the exception: local constants are allowed in blocks. See core 3.1, 3.3, and 15.

## Example

```xo
fn f() -> Int {
  fn g() -> Int { 1 }
  g()
}
```

## Fix

```xo
fn f() -> Int {
  let g = fn() -> Int { 1 }
  g()
}
```

Run `xo explain XO0167` for this text in a terminal, or see
[section 10.6 of the specification](../../spec/core/#106-diagnostic-codes).

