v0.13.7
errors and warnings / types

errors and warnings / types / E2040

E2040 error

Forbidden operation on a possibly secret value (strict mode)

area
types (x2xxx)
fails the build
yes
in plain Lua files
reported as W2040

Strict mode: the value may be a secret value, and this operation raises an error on one. Since Midnight, many APIs give addon code secrets in combat, encounters and Mythic+; arithmetic, comparison, #, indexing, calling, use as a table key and testing a secret boolean all raise at once. Pass the value straight to a widget that accepts secrets (StatusBar:SetValue, FontString:SetText), or narrow it first with canaccessvalue(v) or not issecretvalue(v).

In basic mode and in plain Lua files it is the warning W2040.

Example

× failswowlua
--!strictlocal hp = UnitHealth("target")if hp < 1000 then    print("low")end
✓ compileswowlua
--!strictlocal hp = UnitHealth("target")if canaccessvalue(hp) and hp < 1000 then    print("low")end

The compiler reports it like this:

error[E2040]: `number | Secret<number>` may be a secret value; narrow it with `canaccessvalue` or `issecretvalue` first
  ┌─ src/main.wowlua:3:4
  │
3 │ if hp < 1000 then
  │    ^^ here
codemessage
W2040Forbidden operation on a possibly secret value (basic mode)

Offline

terminal
$ wowlua explain E2040
E2040 (error): Forbidden operation on a possibly secret value (strict mode)

source on GitHub ↗