LYR-SEM0146
a 'return' in a function returning 'never'
A function whose return type is 'never' contains a 'return', other than one returning a call that itself does not return.
Explanation
A function returning never promises that it does not return: every path ends in a panic, a throw, an endless loop, or a call of another never function. A return breaks that promise, and the caller's code after the call would run after all.
End the path with a panic, a throw or a call that does not return, or change the return type.
Wrong
fn stop(): never {
return;
}
fn main(): void {
stop();
}
Right
fn stop(): never {
panic("stopped");
}
fn main(): void {
stop();
}