E1031#
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
:
{
// ...
"warn-list": "+31"
}
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())
}