lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Generics, inheritance and an overloaded constructor

Open skaarj1989 opened this issue 1 year ago • 0 comments

VisualStudio Code on Windows, lua-language-server v3.7.4 (Last updated 2024-01-07, 10:29:54)

The following error occurs only when a generic inherits from a type containing an overloaded constructor.

image

local e = Entity()
e:get(Transform2)
e:get(Transform)

The only difference between Transform and Transform2 is the overloaded constructor.

I could "workaround" this issue by removing : ComponentBase from the function Entity:get ... but I want to check whether the given component type is valid.


Here is the simplified annotation file:

---@class ComponentBase

---@class Transform: ComponentBase
Transform = {}

---@class Transform2: ComponentBase
---@overload fun(x: number, y: number): Transform2
Transform2 = {}

---@class Entity
---@overload fun(): Entity
Entity = {}

---@generic T: ComponentBase
---@param type T
---@return T
function Entity:get(type) end

skaarj1989 avatar Feb 22 '24 16:02 skaarj1989