v0.13.7
errors and warnings / types

errors and warnings / types / E2053

E2053 error

Recursive type alias not guarded by a table or function type

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

A type alias refers to itself outside a table or function type, so it never becomes a type: type A = A | nil, or two aliases that name each other (type B = C, type C = B). A recursive alias is fine inside a table or function type: type Tree = { value: number, children: Tree[] }.

Example

× failswowlua
type Node = Node | nillocal n: Node = nilprint(n)
✓ compileswowlua
type Node = { value: number, next: Node? }local n: Node = { value = 1 }print(n.value)

The compiler reports it like this:

error[E2053]: the type alias `Node` refers to itself outside a table or function type (`Node` → `Node`), so it never becomes a type
  ┌─ src/main.wowlua:1:6
  │
1 │ type Node = Node | nil
  │      ^^^^ write the recursion inside `{ … }` or a function type

Offline

terminal
$ wowlua explain E2053
E2053 (error): Recursive type alias not guarded by a table or function type

source on GitHub ↗