errors and warnings / types / E2009
E2009 error
Not all code paths return a value
- area
- types (x2xxx)
- fails the build
- yes
- in plain Lua files
- reported as W2009
A function that declares results can reach its end without a return, so on
that path it gives nil. Add the missing return, often at the end of the
function, or include nil in the result type (: number?) if giving nothing
is meant.
Example
local function sign(n: number): number if n > 0 then return 1 elseif n < 0 then return -1 endendprint(sign(2))local function sign(n: number): number if n > 0 then return 1 elseif n < 0 then return -1 end return 0endprint(sign(2))The compiler reports it like this:
error[E2009]: not all code paths return a value ┌─ src/main.wowlua:7:1 │ 7 │ end │ ^^^ here
Related codes
| code | message |
|---|---|
| E2001 | Type mismatch: S is not assignable to T |
Offline
$ wowlua explain E2009 E2009 (error): Not all code paths return a value