DiagnosticsError codes
M0010 missing return
A function with results can reach its closing brace without a return statement.
example $ marmot build . error[M0010]: missing return --> ./main.go:7:1 | 7 | } | ^ | = help: add a `return` at the end of the function, or `panic` if the end cannot be reached error: build failed with 1 error for more about an error, run `marmot explain M0010`
The program that produced it
package main
func sign(x int) int {
if x < 0 {
return -1
}
}
func main() {}
The mistake and the fix
func sign(x int) int {
if x < 0 {
return -1
}
}func sign(x int) int {
if x < 0 {
return -1
}
return 1
}The fix
Add a return at the end, or a panic for a case that cannot happen.
See also all error codes and marmot explain.