You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type inference not working for @field and @type function declarations in method overrides #3367
When a child class overrides a parent class method that was declared using @field or @type annotations, the parameter types should be correctly inferred from the parent class definition.
---@classBufflocalmt= {}
---@type (fun(self: Buff, target: Buff): boolean)?mt.on_cover=nil---@classBuff.CommandAura:Bufflocaltpl= {}
functiontpl:on_cover(target)
-- Expected: target type should be Buffreturnself.level>target.levelend
Actual Behaviour
The parameter types are inferred as any instead of the types defined in the parent class.
---@classBufflocalmt= {}
---@type (fun(self: Buff, target: Buff): boolean)?mt.on_cover=nil---@classBuff.CommandAura:Bufflocaltpl= {}
functiontpl:on_cover(target)
-- Actual: target type is any ❌returnself.level>target.levelend
This also affects @field declarations:
---@classAnimal---@fieldcan_eat (fun(self: Animal, other: Animal): boolean)?localbase= {}
---@classDog:Animallocaldog= {}
functiondog:can_eat(other)
-- Actual: other type is any ❌returntrueend
Reproduction steps
Define a parent class with a method using @type or @field annotation
Create a child class that inherits from the parent
Override the method in the child class
Check the parameter types - they will be any instead of the parent's types
Additional Notes
This issue is related to #2569, but specifically focuses on field-style function declarations (@field and @type) rather than method declarations (function Class:method()).
PR #2859 successfully implemented type inference for method declaration style overrides, but did not cover field-style declarations.
Root cause: In script/vm/compiler.lua, the compileFunctionParam function only checks for 'doc.type.function' and 'function' node types, but @field nodes have type 'doc.field' with the actual function type stored in the extends property.
Activity
feat: support type inference for @field and @type function declaratio…