E0031

E0031#

Warning name: unused_optional_argument

The optional argument is never supplied. If the optional argument is never supplied, then it can be safely removed from the parameter list and be used purely internally as a normal variable.

Erroneous example#

Note, this warning is turned off by default. To enable this warning, you have to modify the "warn-list" of moon.pkg.json:

moon.pkg.json#
{
  "is_main": true,
  "warn-list": "+unused_optional_argument"
}
main.mbt#
///|
fn f(opt~ : Int = 4) -> Int {
  ignore(opt)
  0
}

///|
fn main {
  println(f())
  println(f())
}

Suggestion#

You can remove the optional argument, and use a local variable definition instead:

///|
fn f() -> Int {
  let opt = 4
  ignore(opt)
  0
}

///|
fn main {
  println(f())
  println(f())
}