v0.13.8
errors and warnings / types

errors and warnings / types / E2011

E2011 error

Access to a private / protected member

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

A private or protected member is used where it isn't visible. A private member is visible only inside its class body (on any instance of the class); a protected one also in subclasses. Use a public method instead, or make the member public if outside code should reach it. The check is compile-time only: nothing stops it at run time.

Example

× failswowlua
class Account    private balance: number = 0endlocal a = Account.new()print(a.balance)
✓ compileswowlua
class Account    private balance: number = 0    function getBalance(): number        return self.balance    endendlocal a = Account.new()print(a:getBalance())

The compiler reports it like this:

error[E2011]: `balance` is private
  ┌─ src/main.wowlua:5:9
  │
5 │ print(a.balance)
  │         ^^^^^^^ here
codemessage
E2003Unknown field or method (also: method defined outside its class body, assignment to the reserved __wowlua key)

Offline

terminal
$ wowlua explain E2011
E2011 (error): Access to a private / protected member

source on GitHub ↗