v0.13.7
errors and warnings / names

errors and warnings / names / E1031

E1031 error

Duplicate type name in the same scope: two (non-ambient) interfaces, or any two of an interface, a type alias, a class and an enum

area
names (x1xxx)
fails the build
yes
in plain Lua files
reported as W1031

Two types with the same name are declared in the same scope: two interfaces, or an interface, a type alias, a class or an enum with the name of another. A type name means one type in a scope. Only ambient declare interface declarations merge (as for the addon namespace); give the other type its own name, or merge the two into one.

A declaration under @if counts only where the build keeps it, so two alternatives for different builds may share a name.

Example

× failswowlua
interface Named    name: stringendinterface Named    id: numberendlocal n: Named = { name = "x" }print(n)
✓ compileswowlua
interface Named    name: string    id: numberendlocal n: Named = { name = "x", id = 1 }print(n)

The compiler reports it like this:

error[E1031]: an interface `Named` is declared twice in this scope
  ┌─ src/main.wowlua:4:11
  │
1 │ interface Named
  │           ----- first declared here
  ·
4 │ interface Named
  │           ^^^^^ declared again here
  │
  = help: a type name means one type in a scope (only ambient `declare interface` declarations merge): rename one of them, or merge the two

Offline

terminal
$ wowlua explain E1031
E1031 (error): Duplicate type name in the same scope: two (non-ambient) interfaces, or any two of an interface, a type alias, a class and an enum

source on GitHub ↗