v0.13.7
errors and warnings / types

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

× failswowlua
local function sign(n: number): number    if n > 0 then        return 1    elseif n < 0 then        return -1    endendprint(sign(2))
✓ compileswowlua
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
codemessage
E2001Type mismatch: S is not assignable to T

Offline

terminal
$ wowlua explain E2009
E2009 (error): Not all code paths return a value

source on GitHub ↗