Skip to content

Commit 8047cd2

Browse files
committed
add: inject-field diagnostic
1 parent 8f34eaf commit 8047cd2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/content/wiki/diagnostics.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,27 @@ local e = nil
473473

474474
</Diagnostic>
475475

476+
<Diagnostic level="Warning">
477+
<Fragment slot="name">
478+
### inject-field
479+
</Fragment>
480+
Triggered when injecting an undefined field into a class instance. This can be solved by adding the [`@field`](/wiki/annotations#field) to the class or by using [`@class`](/wiki/annotations#class) directly on the instance.
481+
482+
```Lua
483+
---@class Car
484+
---@field topSpeed number
485+
---@field seats integer
486+
487+
---@type Car
488+
local myCar = { topSpeed = 180, seats = 5 }
489+
490+
-- wheels was not defined in the Car class
491+
-- because myCar was marked an instance of Car outside the definition of the Car class, its fields are strictly enforced
492+
myCar.wheels = 6
493+
```
494+
495+
</Diagnostic>
496+
476497
<Diagnostic level="Warning">
477498
<Fragment slot="name">
478499
### need-check-nil

0 commit comments

Comments
 (0)