v0.13.7
errors and warnings / types

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

× failswowlua
--!strictlocal function make(): { x: number }    return { x = 1 }endlocal p = make()p.y = 2
✓ compileswowlua
--!strictlocal function make(): { x: number, y?: number }    return { x = 1 }endlocal p = make()p.y = 2

The 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
codemessage
E2003Unknown field or method (also: method defined outside its class body, assignment to the reserved __wowlua key)

Offline

terminal
$ wowlua explain E2051
E2051 (error): Unknown field added to a sealed table (strict mode)

source on GitHub ↗