E4109

E4109#

Return must be inside a function.

This error occurs when a return statement is used outside of a function. In MoonBit, return statements must be inside a function body.

Erroneous example#

///|
pub let x : Int = {
  return 42
}
//                 ^^^^^^^^^ Error: Return must be inside a function.

///|
pub let y : Int = if x == 42 {
  x + 1
} else {
  return 0
  //  ^^^^^^^^ Error: Return must be inside a function.
}

Suggestion#

To fix this error, you can remove the return statement from the let binding:

///|
pub let x : Int = 42

///|
pub let y : Int = if x == 42 { x + 1 } else { 0 }