errors and warnings / names / E1004
E1004 error
A parameter's default reads that parameter or a later one, which is not set yet (in Lua every parameter is in scope there, so the name is the parameter, not an outer one)
- area
- names (x1xxx)
- fails the build
- yes
- in plain Lua files
- reported as W1004
A parameter's default value reads that parameter or a later one. Every
parameter is in scope in a default, as in the Lua it compiles to, so the
name means the parameter itself, which isn't set yet: it is nil there,
even when an outer local has the same name. A default may read earlier
parameters only. Reorder the parameters, or rename the parameter to read an
outer local of that name.
Example
local function resize(width: number = height, height: number = 100) print(width, height)endresize()local function resize(height: number = 100, width: number = height) print(width, height)endresize()The compiler reports it like this:
error[E1004]: `height` here is the parameter, which is not set yet (a default reads only earlier parameters); to read an outer `height`, give the parameter another name ┌─ src/main.wowlua:1:39 │ 1 │ local function resize(width: number = height, height: number = 100) │ ^^^^^^ here
Related codes
| code | message |
|---|---|
| W1004 | Local shadows another local, or a local function is named like a local of the same block; also a parameter named self inside a class's method or constructor, which hides the instance (a plain function M:m()'s self may be shadowed, as frame handlers do) |
Offline
$ wowlua explain E1004 E1004 (error): A parameter's default reads that parameter or a later one, which is not set yet (in Lua every parameter is in scope there, so the name is the parameter, not an outer one)