errors and warnings / names / E1006
E1006 error
A function reads or assigns a global that a file-level local of the same name, declared further down, hides after it (strict mode)
- area
- names (x1xxx)
- fails the build
- yes
- in plain Lua files
- reported as W1006
A function names a file-level local (or const, local function) that is
declared further down the file, after the function. As in Lua, the function
can't see that local: the name there is the global of the same name, and
that global exists (the game declares it, or the package assigns it). So the
function quietly uses the game's value, not yours. GLYPHS, for example, is
the client's string "Glyphs". Move the declaration above the function, or
write _G.GLYPHS if you mean the global. (In basic mode this is the warning
W1006.) Code at the file's top level runs before the declaration, so reading
the global there, as in local print = print, is fine.
Example
--!strictlocal function texture(name: string): string return GLYPHS .. nameend local GLYPHS = "Interface\\AddOns\\MyAddon\\Glyphs\\"print(texture("star"), GLYPHS)--!strictlocal GLYPHS = "Interface\\AddOns\\MyAddon\\Glyphs\\" local function texture(name: string): string return GLYPHS .. nameendprint(texture("star"))The compiler reports it like this:
error[E1006]: `GLYPHS` here reads the global `GLYPHS`: the file-level local `GLYPHS` is declared further down, after this function ┌─ src/main.wowlua:3:12 │ 3 │ return GLYPHS .. name │ ^^^^^^ the global · 6 │ local GLYPHS = "Interface\\AddOns\\MyAddon\\Glyphs\\" │ ------ the local, declared here │ = help: move the declaration above the function; to mean the global, write `_G.GLYPHS`
Related codes
| code | message |
|---|---|
| W1006 | A function reads or assigns a global that a file-level local of the same name, declared further down, hides after it (basic mode) |
| E1001 | Undefined global read (strict mode) |
Offline
$ wowlua explain E1006 E1006 (error): A function reads or assigns a global that a file-level local of the same name, declared further down, hides after it (strict mode)