v0.13.7
errors and warnings / names

errors and warnings / names / E1040

E1040 error

@if condition is not a static condition

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

An @if condition isn't static: it reads a runtime value such as a local, or @if is given more than one condition. Conditions may use wowlua:meta paths (flavor, build.debug, features.x, config.x), constants and literals. On an import, only wowlua:meta paths and literals are allowed, not consts, because each flavor's import graph is built before constants are evaluated. For a runtime decision, use an ordinary if.

Example

× failswowlua
local verbose = true @if(verbose)local function dumpState()    print("state")end
✓ compileswowlua
import build from "wowlua:meta" @if(build.debug)local function dumpState()    print("state")end if build.debug then    dumpState()end

The compiler reports it like this:

error[E1040]: `@if` conditions must be static: `wowlua:meta` paths, constants and literals
  ┌─ src/main.wowlua:3:5
  │
3 │ @if(verbose)
  │     ^^^^^^^ here
codemessage
E1039@if(flavor …) in a .wowlua file in shared flavor mode
E1020Reference to a declaration removed by @if or static elimination

Offline

terminal
$ wowlua explain E1040
E1040 (error): @if condition is not a static condition

source on GitHub ↗