LuaLS / LuaLS/lua-language-server
Class Inheritance Triggers Typing Issues
まだ誰も着手していません。
- 主要言語
- 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
- Create a superclass:
---@class MySuperclass
local o = {}
- Create a subclass:
---@class MySubclass : MySuperclass
local o = {}
- Create a function that returns MySuperclass
- 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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Windows 上の Visual Studio Code 拡張機能を通じて issue にあるスーパークラスとサブクラスの例を再現し、MySuperclass の結果を MySubclass に代入する際の型チェック診断に焦点を当てます。クラス継承に関係する型チェックの動作を追跡し、修正が完了した時点で、@cast を要求せずに代入が受け入れられることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100