Xo is experimental. The source code is not public yet; it will be soon. Read the release notes
Menu · XO0167

Docs

XO0167: top level declaration inside a block

error · reported by the parser

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

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

Fix

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.