E0032#
Warning name: unused_default_value
Default value of optional argument is unused. This implies at every call site of this function, the optional argument is always explicitly supplied with a value. This means the optional argument can be refactored into a labelled argument.
Erroneous example#
Note, this warning is turned off by default. To enable this warning, you need to modify the "warn-list" of moon.pkg.json:
moon.pkg.json#
{
"is_main": true,
"warn-list": "+unused_default_value"
}
main.mbt#
///|
fn f(opt~ : Int = 4) -> Int {
ignore(opt)
0
}
///|
fn main {
println(f(opt=3))
println(f(opt=3))
}
Suggestion#
Turn the optional argument into a labelled argument:
///|
fn f(opt~ : Int) -> Int {
ignore(opt)
0
}
///|
fn main {
println(f(opt=3))
println(f(opt=3))
}