v0.13.7
errors and warnings / classes

errors and warnings / classes / E3021

E3021 error

Decorator not applicable to this target (including user decorators on enums, interfaces and aliases)

area
classes (x3xxx)
fails the build
yes

A decorator is used on a declaration it can't apply to. User decorators work on functions, classes and class members; on enums, interfaces, type aliases, declare statements and imports they can't take effect (enum members are inlined, types have no value at run time). Each core decorator has its own targets: @script only on instance methods of widget classes, @inline and @debugOnly on functions and methods, and so on. The code also covers a @script without a script name or with options other than { hook = true } or { hook = false }.

Example

× failswowlua
@script("OnClick")local function clicked()endclicked()
✓ compileswowlua
class Clicker extends Button    @script("OnClick")    function clicked()        print("clicked")    endendprint(Clicker)

The compiler reports it like this:

error[E3021]: `@script` cannot be applied to functions
  ┌─ src/main.wowlua:1:1
  │
1 │ @script("OnClick")
  │ ^^^^^^^^^^^^^^^^^^ here
codemessage
E3020Unknown decorator
E0109Decorator not followed by a decoratable declaration

Offline

terminal
$ wowlua explain E3021
E3021 (error): Decorator not applicable to this target (including user decorators on enums, interfaces and aliases)

source on GitHub ↗