LuaLS / LuaLS/lua-language-server

Inheriting from a generic class, which uses an annotated table definition causes fields to get lost

Open
#3,443 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### How are you using the lua-language-server?

NeoVim

### Which OS are you using?

Windows

### What is the issue affecting?

Annotations, Type Checking

### Expected Behaviour

```lua
--- (field) Specific.value: string
hover(t.value)
```

### Actual Behaviour

```lua
--- (field) Specific.value: unknown
hover(t.value)
```

### Reproduction steps

```lua
---@class GenericSuper : { value: T }

---@class Specific : GenericSuper

---@type Specific
local t

hover(t.value)
```
Then hover on `t.value`

### Additional Notes

Interestingly this seems to only affect inheriting from table constructor. When converting it into a field, it works as expected:
```lua
---@class GenericSuper
---@field value T

---@class Specific : GenericSuper

---@type Specific
local t

--- (field) Specific.value: string
hover(t.value)
```

### Log File

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue in NeoVim using the GenericSuper table constructor and the Specific : GenericSuper inheritance shown in the report. Compare hover results for the table-constructor form and the equivalent @field form; done means t.value is inferred as string in the inherited table-constructor case.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.