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
class Animal name: string = "Rex"endlocal a = Animal.new()print(a.nmae)class Animal name: string = "Rex"endfunction Animal:speak() print(self.name)endclass 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
Related codes
| code | message |
|---|---|
| W2003 | Unknown field or method (also: method defined outside its class body, assignment to the reserved __wowlua key) (in a plain Lua file) |
| E2051 | Unknown field added to a sealed table (strict mode) |
| E2011 | Access to a private / protected member |
Offline
$ wowlua explain E2003 E2003 (error): Unknown field or method (also: method defined outside its class body, assignment to the reserved __wowlua key)