v0.13.7
errors and warnings / types

errors and warnings / types / E2001

E2001 error

Type mismatch: S is not assignable to T

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

A value's type doesn't fit where it is used: an argument, an assignment to a local or field, or a return value. The same code covers an operator used on a type it doesn't take, such as comparing a number with a string or doing arithmetic on a boolean. Change the value, or widen the annotation if the value is right.

A local without an annotation takes the type of the value it is declared with (local test = 3 is a number), and later assignments must fit that type as if it were written out. To hold other values too, annotate it (local test: number | string = 3). A local declared without a value, or with nil, holds whatever is assigned to it.

In a plain Lua file (no wowlua syntax, no --!strict) the checker reports the warning with the same number, W2001, so existing code keeps building.

Example

× failswowlua
local count: number = "3"print(count)
✓ compileswowlua
local count: number = 3print(count)
× failswowlua
local test = 3test = "hello world"print(`test: {test}`)
✓ compileswowlua
local test: number | string = 3test = "hello world"print(`test: {test}`)

The compiler reports it like this:

error[E2001]: `"3"` is not assignable to `number`
  ┌─ src/main.wowlua:1:7
  │
1 │ local count: number = "3"
  │       ^^^^^ here
codemessage
W2001Type mismatch: S is not assignable to T (in a plain Lua file)
E2005Value may be nil (strict mode)

Offline

terminal
$ wowlua explain E2001
E2001 (error): Type mismatch: S is not assignable to T

source on GitHub ↗