LuaLS / LuaLS/lua-language-server
string.unpack vararg returns
まだ誰も着手していません。
- 主要言語
- 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?
Linux
What is the issue affecting?
Annotations, Type Checking, Completion
Expected Behaviour
The current string.unpack annotations (for the returns) are as following:
---@param fmt string
---@param s string
---@param pos? integer
---@return any ...
---@return integer offset
---@nodiscard
function string.unpack(fmt, s, pos) end
The function will indeed return any number of any returns followed by a single integer return for the new offset. As such you would expect that in the following example code, all of the returns are any except the last return be integer:
local a, b, c, d, offset = string.unpack('I2I2I2I2', "some binary data")
Actual Behaviour
Instead of the a, b, c, d being typed as any and offset being typed as integer, we instead see that a is typed as any, b is typed as integer, and c, d, offset are typed as nil.
This happen because it is not supported for a function to return a vararg followed by any return; it is always that vararg returns are the last return. Because of that, only the first return is typed as any and from there the second @return takes.
Reproduction steps
- Copy the example code.
- Hover over each return variable to notice the type.
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
string.unpack のアノテーションから始め、返される各変数にホバーして Visual Studio Code 拡張機能で問題を再現します。型チェッカーが vararg に続く offset の戻り値をどのように処理するかを追跡します。unpack の値が any として型付けされ、最後の offset が integer として型付けされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100