LuaLS / LuaLS/lua-language-server

Generics, inheritance and an overloaded constructor

Open
#2,534 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the simplified annotation file in the issue and reproduce the diagnostic in Visual Studio Code on Windows using lua-language-server v3.7.4. Compare the generic Entity:get calls for Transform and Transform2, then verify that the valid component types are handled consistently without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.