v0.13.7
errors and warnings / names

errors and warnings / names / E1002

E1002 error

Implicit global assignment (strict mode)

area
names (x1xxx)
fails the build
yes
in plain Lua files
reported as W1002

In strict mode, the code assigns a global that isn't declared, including through function name() in a script. Accidental globals are a classic addon bug: they leak into every addon's environment, can collide with other addons' names and can taint Blizzard code. Make it local if only this file needs it, export it from a module, or declare a real global (declare global name: T). Writing _G.name = value is always allowed.

In basic mode the same assignment is the warning W1002.

Example

× failswowlua
--!strictcounter = 0
✓ compileswowlua
--!strictdeclare global MyAddonCounter: numberMyAddonCounter = 0

The compiler reports it like this:

error[E1002]: assigns the undeclared global `counter` (declare it, use `_G.counter`, or make it `local`)
  ┌─ src/main.wowlua:2:1
  │
2 │ counter = 0
  │ ^^^^^^^ here
codemessage
W1002Implicit global assignment (basic mode)
E1001Undefined global read (strict mode)

Offline

terminal
$ wowlua explain E1002
E1002 (error): Implicit global assignment (strict mode)

source on GitHub ↗