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 (x~ : ) ->  {
  ()
}

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

///|
pub fn () ->  {
  fn ( : ) ->  {
    ()
  }
  (42)
}