v0.13.7
errors and warnings / classes

errors and warnings / classes / E3042

E3042 error

Field and method/accessor with the same name (in a class or across its superclass)

area
classes (x3xxx)
fails the build
yes

A field and a method (or accessor) with the same name, in one class or across a class and its superclass. An instance has one value per name, so the field would hide the method. Rename one of them.

Example

× failswowlua
class Unit    function label(): string        return "x"    endendclass Player extends Unit    label: string = "y"endprint(Player)
✓ compileswowlua
class Unit    function label(): string        return "x"    endendclass Player extends Unit    title: string = "y"endprint(Player)

The compiler reports it like this:

error[E3042]: `label` is a field in one class and a method or accessor in the other
  ┌─ src/main.wowlua:7:5
  │
2 │     function label(): string
  │              ----- inherited member
  ·
7 │     label: string = "y"
  │     ^^^^^ here
codemessage
E3046A field declared twice in one class (a constructor's parameter property included)

Offline

terminal
$ wowlua explain E3042
E3042 (error): Field and method/accessor with the same name (in a class or across its superclass)

source on GitHub ↗