LYR-SEM0017
a path of a function that returns no value
A function whose return type is not void has a path that reaches the end of its body without a return or a throw. A function returning never whose body can end, and a coroutine whose result is not returned on every path, are reported here too.
Explanation
A function that declares a result gives it on every path. The check follows the control flow: an if without an else, a loop that may end, or a break before the return all leave a path open.
Add the missing return (or a throw), usually at the end of the body.
Wrong
fn sign(n: int): int {
if (n < 0) { return -1; }
if (n > 0) { return 1; }
}
fn main(): void {
let _ = sign(2);
}
Right
fn sign(n: int): int {
if (n < 0) { return -1; }
if (n > 0) { return 1; }
return 0;
}
fn main(): void {
let _ = sign(2);
}