errors and warnings / types / W2040
W2040 warning
Forbidden operation on a possibly secret value (basic mode)
- area
- types (x2xxx)
- fails the build
- with --deny-warnings
The basic-mode warning for E2040: the value may be a secret value, and this
operation raises an error on one in game (arithmetic, comparison, #,
indexing, calling, use as a table key, testing a secret boolean). It is a
warning in basic mode and in plain Lua files, an error under --!strict.
Narrow the value with canaccessvalue(v) or not issecretvalue(v) first.
Example
local hp = UnitHealth("target")if hp < 1000 then print("low")endlocal hp = UnitHealth("target")if canaccessvalue(hp) and hp < 1000 then print("low")endThe compiler reports it like this:
warning[W2040]: `number | Secret<number>` may be a secret value; narrow it with `canaccessvalue` or `issecretvalue` first ┌─ src/main.wowlua:2:4 │ 2 │ if hp < 1000 then │ ^^ here
Related codes
| code | message |
|---|---|
| E2040 | Forbidden operation on a possibly secret value (strict mode) |
Offline
$ wowlua explain W2040 W2040 (warning): Forbidden operation on a possibly secret value (basic mode)