LuaLS / LuaLS/lua-language-server
Generics don't expand alias types/don't work with other parameters
まだ誰も着手していません。
- 主要言語
- 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
Expected Behaviour
With a code sample like this:
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@param func T
local function testSecond(name, func) end
testSecond("TestFunction", function(abc) end)
I would expect abc to have a type of string, and the function to be type checked and require a return.
Actual Behaviour
Instead, abc has the any type and the function requires no return.
I further tested with a different code sample:
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@return T
local function testSecond(name, func) return function(abc) end end
local cool = testSecond("TestFunction", function(abc) end)
cool()
This shows no warnings and does not require me to pass any arguments to cool(), which is incorrect. Hovering over cool provides a type of 'TestFunction' and does not show the full expanded type of the alias, unlike other variables with a type of an alias. That rings the same with this code sample I also tested:
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@param func fun(cool: T)
local function testSecond(name, func) end
testSecond("TestFunction", function(abc) end)
where hovering over abc provides me with a 'TestFunction' unexpanded type.
However, correct behavior is seen with the following code sample using the base string type;
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@param func fun(cool: T)
---@return T
local function testSecond(name, func) end
local cool = testSecond("string", function(abc) abc.cool = "hi" end)
local testfind = cool:find("test")
Autocomplete is provided for :find() and abc.cool = "hi" throws the correct warning for field injection.
And most confusing of all, this code sample behaves in line with expected behavior, and the alias is fully expanded.
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@param func fun(cool: T)
---@return T
local function testSecond(name, func) end
local cool = testSecond("TestFunction",
---@param abc TestFunction
function(abc)
abc()
end
)
This also doesn't work, which I kind of expected. (no warnings)
Reproduction steps
- Paste code into project with Lua LSP on, see issue
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、LuaLS を使用する Visual Studio Code Extension の例を再現し、ジェネリックパラメーターと aliased function types の型チェックに焦点を当てます。TestFunction を使用するケースと、基底の string 型を使用するケースを比較します。エイリアスが一貫して展開され、コールバックパラメーターが期待される型を受け取り、無効な呼び出しや戻り値の不足によって警告が生成されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100