E4114

E4114#

Only toplevel functions can have labelled arguments.

This error occurs when trying to use labelled arguments in a local function or anonymous function.

Erroneous example#

///|
pub fn f() -> Unit {
  fn h(x~ : Int) -> Unit {
    //     ^^ Error: Only toplevel functions can have labelled arguments.
    println(x)
  }
  h(x=42)
}

Suggestion#

To fix this error, you can either:

  • Move the function to the top level of the module

///|
fn h(x~ : Int) -> Unit {
  println(x)
}

///|
pub fn call_toplevel() -> Unit {
  h(x=42)
}
  • Remove the labelled arguments

///|
pub fn call_positional() -> Unit {
  fn h(x : Int) -> Unit {
    println(x)
  }
  h(42)
}