v0.13.7
errors and warnings / types

errors and warnings / types / W2062

W2062 warning

A value read past what a function of the package can give (a local function, a module's or an imported function, a file-level table's method; (each of its returns a fixed number of values) is always nil: a name past them in a local or an assignment, or select(n, …) with a literal n past them; and a name past an and or or of a call ending a local or an assignment (local x, y = pos and pos:GetXY(): the operator keeps one value, decision L73) (any mode)

area
types (x2xxx)
fails the build
with --deny-warnings

A name reads past the values a function gives, so it is always nil. The checker counts the values of the package's own functions whose every return gives a fixed number of them (local functions, a module's functions, imported ones, methods of a file-level table). It also reports a name past an and or or that ends a local or an assignment, since those give one value: in local x, y = pos and pos:GetXY(), y is always nil. Fix the names, or write if pos then x, y = pos:GetXY() end. Names starting with _ are skipped.

Example

× failswowlua
local function pos()    return 1, 2endlocal x, y, z = pos()print(x, y, z)
✓ compileswowlua
local function pos()    return 1, 2endlocal x, y = pos()print(x, y)

The compiler reports it like this:

warning[W2062]: `pos` gives at most 2 values: `z` is always nil
  ┌─ src/main.wowlua:4:13
  │
4 │ local x, y, z = pos()
  │             ^ here

Offline

terminal
$ wowlua explain W2062
W2062 (warning): A value read past what a function of the package can give (a local function, a module's or an imported function, a file-level table's method; (each of its returns a fixed number of values) is always nil: a name past them in a local or an assignment, or select(n, …) with a literal n past them; and a name past an and or or of a call ending a local or an assignment (local x, y = pos and pos:GetXY(): the operator keeps one value, decision L73) (any mode)

source on GitHub ↗