Skip to content

generic inheritance does not work #1272

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
RomanSpector opened this issue Jul 2, 2022 · 1 comment
Open

generic inheritance does not work #1272

RomanSpector opened this issue Jul 2, 2022 · 1 comment
Labels
enhancement New feature or request feat/generic Related to generic emulation feature feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)

Comments

@RomanSpector
Copy link

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,

image

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

image

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

image

and there is no error either

image

@RomanSpector RomanSpector changed the title genetic inheritance does not work generic inheritance does not work Jul 2, 2022
@sumneko sumneko added enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) labels Jul 2, 2022
@sumneko
Copy link
Collaborator

sumneko commented Jul 2, 2022

Need to add cross type features:

---@generic T
---@param name `T`
---@return T & Rotation rotation
function Core.RotationEngine.AddRotation(name) end

@carsakiller carsakiller added the feat/generic Related to generic emulation feature label Jan 30, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request feat/generic Related to generic emulation feature feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)
Projects
None yet
Development

No branches or pull requests

3 participants