LuaLS / LuaLS/lua-language-server
Support for a bottom type for non-returning functions
まだ誰も着手していません。
- 主要言語
- 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
Have a way to tag the return type of a function as Bottom, i.e., never returns.
Actual Behaviour
I have a snippet like this:
local function abort(err)
io.stderr:write(err .. "\n")
os.exit(1)
end
local function stuff()
local chunk = loadfile("x.lua")
if not chunk then
abort("failed to loadfile()")
end
chunk()
return {}
end
stuff()
which triggers the "need-nil-check" diagnostic on "chunk()" because it doesn't understand that abort() never returns, so i would like to tag abort() (or better tag os.exit() and do return os.exit) as never returning function.
obvious work-around is to do "return abort(...)" instead, but that messes up the return type of stuff() from table to table|nil. so i have to write abort() return {} to make the type checker happy which is a bit cumbersome
Reproduction steps
- Go to '...'
- Click '...'
- See error '...'
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
need-nil-check 診断の型チェック経路と、既存の関数戻り値アノテーションから始めます。abort と os.exit に対して求められている扱いを、呼び出し後にチェッカーが stuff() をどのように推論するかと比較します。完了の条件は、stuff() の戻り値型に nil を追加せずに nil 診断を回避できるよう、戻らない関数を表現できることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100