errors and warnings / types / E2051
E2051 error
Unknown field added to a sealed table (strict mode)
- area
- types (x2xxx)
- fails the build
- yes
- in plain Lua files
- reported as W2051
Strict mode: a field is added to a sealed table, one whose type is fixed. A
table literal stays open (fields can be added) while it is a local in the
function that made it; it is sealed once it escapes (passed, returned, stored
or captured) and when its type comes from an annotation. Declare the field in
the type, write it in the literal, or give the type an indexer
([string]: V). Basic mode allows it.
Example
--!strictlocal function make(): { x: number } return { x = 1 }endlocal p = make()p.y = 2--!strictlocal function make(): { x: number, y?: number } return { x = 1 }endlocal p = make()p.y = 2The compiler reports it like this:
error[E2051]: cannot add the field `y` to a sealed table ┌─ src/main.wowlua:6:3 │ 6 │ p.y = 2 │ ^ here
Related codes
| code | message |
|---|---|
| E2003 | Unknown field or method (also: method defined outside its class body, assignment to the reserved __wowlua key) |
Offline
$ wowlua explain E2051 E2051 (error): Unknown field added to a sealed table (strict mode)