lua-language-server
lua-language-server copied to clipboard
`generic` inheritance does not work
The second case
Core = {};
---@class Rotation
---@field Enabled boolean
local Rotation = {}
function Rotation:OnLoad() end
function Rotation:OnUnload() end
---@class RotationEngine
Core.RotationEngine = {}
---@generic T
---@param name `T`
---@return T|Rotation rotation
function Core.RotationEngine.AddRotation(name) end
---@class MyRotation
---@field testfield table
local MyRotation = {};
function MyRotation:Test() end
local rotation = Core.RotationEngine.AddRotation("MyRotation");
---@param self MyRotation
---@return boolean
local function myFunc(self) end
local a = myFunc(rotation);
In the first case, in the MyRotation class, we seek methods of the Rotation class,

but also an error Cannot assign MyRotation|Rotation to parameter MyRotation.Lua Diagnostics.(param-type-mismatch)

The second case
Core = {};
---@class Rotation
---@field Enabled boolean
local Rotation = {}
function Rotation:OnLoad() end
function Rotation:OnUnload() end
---@class RotationEngine
Core.RotationEngine = {}
---@generic T: Rotation
---@param name `T`
---@return T rotation
function Core.RotationEngine.AddRotation(name) end
---@class MyRotation
---@field testfield table
local MyRotation = {};
function MyRotation:Test() end
local rotation = Core.RotationEngine.AddRotation("MyRotation");
---@param self MyRotation
---@return boolean
local function myFunc(self) end
local a = myFunc(rotation);
In the second case there is no inheritance

and there is no error either

Need to add cross type features:
---@generic T
---@param name `T`
---@return T & Rotation rotation
function Core.RotationEngine.AddRotation(name) end