v0.13.7
errors and warnings / names

errors and warnings / names / W1034

W1034 warning

Name read at load time but only defined at run time

area
names (x1xxx)
fails the build
with --deny-warnings

A file reads a global (or an addon-namespace field) while it loads, but the only definitions of that name run later, inside functions such as event handlers. When the file loads in game the value is still nil. Define the name at the top level of its file, or move the read into code that runs after the definition (the same event, or a later one).

Example

× failssrc/a.lualua
local frame = CreateFrame("Frame")frame:RegisterEvent("PLAYER_LOGIN")frame:SetScript("OnEvent", function()    MyAddonDB = {}end)
src/b.lualua
print(MyAddonDB)
✓ compilessrc/a.lualua
local frame = CreateFrame("Frame")frame:RegisterEvent("PLAYER_LOGIN")frame:SetScript("OnEvent", function()    MyAddonDB = {}end)
src/b.lualua
local frame = CreateFrame("Frame")frame:RegisterEvent("PLAYER_LOGIN")frame:SetScript("OnEvent", function()    print(MyAddonDB)end)

The compiler reports it like this:

warning[W1034]: `MyAddonDB` is read while the file loads, but only defined later (inside functions that run at run time)
  ┌─ src/b.lua:1:7
  │
1 │ print(MyAddonDB)
  │       ^^^^^^^^^ read at load time
codemessage
W1033Load order cannot be determined (dynamic names, several writers, external names); files keep their source order
E1014Import or usage cycle containing a load-time edge (run-time-only cycles are allowed)

Offline

terminal
$ wowlua explain W1034
W1034 (warning): Name read at load time but only defined at run time

source on GitHub ↗