Skip to content

generic inheritance does not work #1272

Open
@RomanSpector

Description

@RomanSpector
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeat/LuaCats AnnotationsRelated to Lua Language Server Annotations (LuaCats)feat/genericRelated to generic emulation feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions