LuaLS / LuaLS/lua-language-server

Support for a bottom type for non-returning functions

未關閉
#2,443 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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

### 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

1. Go to '...'
2. Click '...'
3. See error '...'

### Additional Notes

_No response_

### Log File

_No response_

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 `need-nil-check` 診斷的型別檢查路徑以及現有的函式回傳型別註解著手。將對 `abort` 和 `os.exit` 所要求的處理方式,與檢查器在呼叫之後如何推斷 `stuff()` 進行比較。完成的標準是:可以表示一個不回傳的函式,從而避免 nil 診斷,而不將 nil 加入 `stuff()` 的回傳型別。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
lua
領域
devtools
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。