go
compile_error
ai_generated
true
missing return at end of function
ID: go/missing-return
98%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Function declares return type but not all code paths return a value.
genericWorkarounds
-
95% success Ensure every code path (every if/else/switch branch) has a return statement
every if/else/switch branch
-
92% success Add a default return after the if/switch to handle the 'else' case
func classify(n int) string { if n > 0 { return "positive" } else if n < 0 { return "negative" } return "zero" // default return covers all paths }
Dead Ends
Common approaches that don't work:
-
Add return at the end with zero value
55% fail
May silently return wrong result — ensure the logic is correct
-
Change return type to not return anything
75% fail
If callers use the return value, this breaks them
Error Chain
Frequently confused with: