Go: ./main.go:18:1: missing return
A function with a return type can reach its end without a return statement on some path.
missing return./main.go: missing returnfunction ends without a return statement Meaning
Go requires every control-flow path of a non-void function to end in a terminating statement (return, panic, an infinite for {}, or an exhaustive switch with default that returns). An if/else chain without final else or a for with a condition does not count.
Common causes
- if/else if chain missing a final return
- Loop with a condition then fall off the end
- switch without a default case
- Return only inside an if
- Function ends with a log call instead of return/panic
⚡ Quick fix
- Add a final
return(orpanic) after the loop or conditional - Add
default:to switch statements - Restructure to return early
Detailed fix by platform
Go
go vet ./...highlights unreachable and missing returns
How to diagnose
- Paths — Every path returns?
- Switch — default present?
- Loop — Can it exit?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- assignment mismatch: 1 variable but f returns 2 values Go: assignment mismatch: 1 variable but os.Open returns 2 values
- cannot assign to struct field m[k].f in map Go: cannot assign to struct field users["bob"].Age in map
- cannot use x as type in assignment/argument Go: cannot use "5" (untyped string constant) as int value in argument to f
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026