LuaLS / LuaLS/lua-language-server
Class Inheritance Triggers Typing Issues
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
### How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
### Which OS are you using?
Windows
### What is the issue affecting?
Type Checking, Diagnostics/Syntax Checking
### Expected Behaviour
To put it in plain terms, this is for a system of UserControls for a settings-panel system. There is a single Superclass, called "MCT.Option", which houses all of the unified behavior of all the UserControls. Then there are subclasses, for each type of UserControl - checkbox, dropdown, etc.
There's an abstracted method on the UserControl "holders", `holder:get_option_by_key("user_control_key')` that I have annotated as returning an MCT.Option. In reality, that superclass is never actually returned in practice - it's purely abstracted, and any option is one of the several subclasses.
So when I call:
```
---@type MCT.Option.Checkbox
local option = holder:get_option_by_key("i_know_this_is_a_checkbox")
```
I'm expecting to very easily call a conversion from superclass -> subclass.
I have all that (I think) I need to tell the debugger that it's a subclass: initial definition of the subclass is `---@class MCT.Option.Checkbox : MCT.Option, Class` to tell it its parents, and it reads from the higher methods and properties completely fine.
But when I call ---@type like that, the debugger doesn't let me simply convert from one to another.
I can of course use `---@cast option MCT.Option.Checkbox` after the variable is defined, but that's a bit clunkier in my opinion than having the type defined above the variable, and it ends up requiring me to reference the variable in the annotation, so it takes a bit longer to write up (and I have a lot of these!)
### Actual Behaviour

### Reproduction steps
1. Create a superclass:
```
---@class MySuperclass
local o = {}
```
2. Create a subclass:
```
---@class MySubclass : MySuperclass
local o = {}
```
3. Create a function that returns MySuperclass
4. Try to direct the type that returns from that function into MySublass
### Additional Notes
Thank you for all the hard work you've done over the years - I've been using this extension for a very very long time and it's truly a lifesaver.
### Log File
[file_s%3A_modding_warhammer_3_groovy_mct.log](https://github.com/LuaLS/lua-language-server/files/10698513/file_s.3A_modding_warhammer_3_groovy_mct.log)
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先,透過 Windows 上的 Visual Studio Code 擴充功能重現 issue 中的超類別和子類別範例,重點關注將 MySuperclass 結果指派給 MySubclass 時的型別檢查診斷。追蹤類別繼承涉及的型別檢查行為,並確認修正完成後,無需 @cast 即可接受該指派。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100