v0.13.7
errors and warnings / names

errors and warnings / names / E1039

E1039 error

@if(flavor …) in a .wowlua file in shared flavor mode

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

@if(flavor …) is used in a .wowlua file in shared flavor mode (build.flavor-mode = "shared"). There, one build runs on every flavor, so flavor is a value known only in game and can't remove declarations at compile time. Test the flavor at run time instead (if flavor == "standard" then … end), or switch to split mode, where each flavor gets its own build. In declaration files @if(flavor …) keeps its meaning.

Example

× failswowlua.jsonjson
{    "package": { "name": "playground", "version": "0.1.0", "wowlua": "^0.13" },    "flavors": { "camelot": {}, "standard": {} },    "build": { "flavor-mode": "shared" }}
src/main.wowluawowlua
import flavor from "wowlua:meta" @if(flavor == "standard")local function setupEditMode()    print("edit mode")end setupEditMode()
✓ compileswowlua.jsonjson
{    "package": { "name": "playground", "version": "0.1.0", "wowlua": "^0.13" },    "flavors": { "camelot": {}, "standard": {} },    "build": { "flavor-mode": "shared" }}
src/main.wowluawowlua
import flavor from "wowlua:meta" local function setupEditMode()    print("edit mode")end if flavor == "standard" then    setupEditMode()end

The compiler reports it like this:

error[E1039]: `flavor` is not a constant in shared flavor mode; use a runtime check
  ┌─ src/main.wowlua:3:5
  │
3 │ @if(flavor == "standard")
  │     ^^^^^^^^^^^^^^^^^^^^ here
codemessage
E1040@if condition is not a static condition
E1020Reference to a declaration removed by @if or static elimination

Offline

terminal
$ wowlua explain E1039
E1039 (error): @if(flavor …) in a .wowlua file in shared flavor mode

source on GitHub ↗