v0.13.7
errors and warnings / stdlib

errors and warnings / stdlib / E8002

E8002 error

@event on an instance method

area
stdlib (x8xxx)
fails the build
yes

@event, @bucket and @unitEvent register a function when the module (or the class) is defined. An instance method has no object at that time, so these decorators can't go on one; on a static method they are fine.

Subscribe in the constructor instead, with on(name, handler, self) (or onBucket / onUnit), and call offAll(self) when the object is discarded.

Example

× failswowlua
import event from "wowlua:events" class Tracker    @event("PLAYER_LOGIN")    function onLogin()        print("logged in")    endend
✓ compileswowlua
import on from "wowlua:events" class Tracker    constructor()        on("PLAYER_LOGIN", function() self:onLogin() end, self)    end     function onLogin()        print("logged in")    endend local tracker = Tracker.new()print(tracker)

The compiler reports it like this:

error[E8002]: `@event` on an instance method: register with `on(…, self)` in the constructor
  ┌─ src/main.wowlua:4:5
  │
4 │     @event("PLAYER_LOGIN")
  │     ^^^^^^^^^^^^^^^^^^^^^^ an instance method
codemessage
E8003Unknown event or message name

Offline

terminal
$ wowlua explain E8002
E8002 (error): @event on an instance method

source on GitHub ↗