Commit 255e83b
When a child class overrides a parent class method that was declared using
@field or @type annotations (instead of function declarations), the parameter
types are now correctly inferred from the parent class.
This extends the existing method override type inference (PR #2859) to support
field-style function declarations.
Example:
```lua
---@Class Buff
local mt = {}
---@type (fun(self: Buff, target: Buff): boolean)?
mt.on_cover = nil
---@Class Buff.CommandAura : Buff
local tpl = {}
function tpl:on_cover(target)
-- target type is now correctly inferred as Buff (was any before)
return self.level > target.level
end
```
Changes:
- Modified compileFunctionParam in script/vm/compiler.lua to extract function
type from doc.field nodes by accessing their extends property
- Added support for doc.type.function in parent class field lookup
- Added comprehensive test cases for @field and @type method overrides
Fixes #3367
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d965edc commit 255e83b
3 files changed
Lines changed: 88 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1353 | 1353 | | |
1354 | 1354 | | |
1355 | 1355 | | |
1356 | | - | |
1357 | | - | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
1358 | 1364 | | |
1359 | | - | |
| 1365 | + | |
1360 | 1366 | | |
1361 | 1367 | | |
1362 | 1368 | | |
| |||
1460 | 1466 | | |
1461 | 1467 | | |
1462 | 1468 | | |
1463 | | - | |
1464 | | - | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
1465 | 1479 | | |
1466 | 1480 | | |
1467 | 1481 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
0 commit comments