LuaLS / LuaLS/lua-language-server
`generic` inheritance does not work
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
The second case
```lua
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
```lua
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

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing both Lua snippets from the issue and compare the inferred type of rotation, method completion, and diagnostics. Trace the generic return-type inference and class-inheritance handling involved in AddRotation. Done means the intended inherited members are available and the incorrect MyRotation|Rotation type mismatch is resolved without losing the second case's behavior.
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