v0.13.7
errors and warnings / types

errors and warnings / types / E2003

E2003 error

Unknown field or method (also: method defined outside its class body, assignment to the reserved __wowlua key)

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

The value has no field or method of that name. Classes are sealed, so every member of a class instance must be declared in the class body, in every mode; a misspelt name is the usual cause. Strict mode also reports a named field read from an array, an unknown field in a table literal written for a record type, and a name the string library doesn't have (s:nope()), all of which Lua would read as nil.

The code has two more meanings. A method defined outside its class body (function Animal:speak() … end after the class) is E2003: move it into the class. And the key __wowlua is reserved for the wowlua runtime, so assigning it on a frame or an instance is E2003 too.

Example

× failswowlua
class Animal    name: string = "Rex"endlocal a = Animal.new()print(a.nmae)
× failswowlua
class Animal    name: string = "Rex"endfunction Animal:speak()    print(self.name)end
✓ compileswowlua
class Animal    name: string = "Rex"    function speak()        print(self.name)    endendlocal a = Animal.new()print(a.name)a:speak()

The compiler reports it like this:

error[E2003]: `Animal` has no field or method `nmae`
  ┌─ src/main.wowlua:5:9
  │
5 │ print(a.nmae)
  │         ^^^^ here
codemessage
W2003Unknown field or method (also: method defined outside its class body, assignment to the reserved __wowlua key) (in a plain Lua file)
E2051Unknown field added to a sealed table (strict mode)
E2011Access to a private / protected member

Offline

terminal
$ wowlua explain E2003
E2003 (error): Unknown field or method (also: method defined outside its class body, assignment to the reserved __wowlua key)

source on GitHub ↗