v0.13.7
errors and warnings / classes

errors and warnings / classes / E3041

E3041 error

... used in a field or static initializer

area
classes (x3xxx)
fails the build
yes

... in a field or static initializer. Field initializers run in the generated __init, not in the constructor's body, so the constructor's ... isn't there. Assign the field in the constructor instead.

Example

× failswowlua
class Bag    items: any[] = { ... }    constructor(...: any)    endendprint(Bag)
✓ compileswowlua
class Bag    items: any[]    constructor(...: any)        self.items = { ... }    endendprint(Bag)

The compiler reports it like this:

error[E3041]: `...` cannot be used in a field initializer
  ┌─ src/main.wowlua:2:22
  │
2 │     items: any[] = { ... }
  │                      ^^^ here

Offline

terminal
$ wowlua explain E3041
E3041 (error): ... used in a field or static initializer

source on GitHub ↗