LuaLS / LuaLS/lua-language-server
Defining optional globals doesn't trigger nil check warning
還沒有人認領這個 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
I have some code that runs in different environments that have different global variables available.
For example, environment1 may have a global table C_GameRules available with a function in it. environment2 does not have the global available.
I'm trying to write a meta file that makes this optional nature of this global available:
```
---@meta
---@type table?
C_GameRules = nil
---@return boolean
function C_GameRules.IsHardcoreActive() end
```
I've also tried to define a class, no change in behavior
### Actual Behaviour
`C_GameRules.IsHardcoreActive()` does not trigger a need-nil-check warning, but the type of C_GameRules gets shown as `table?`
### Reproduction steps
see above
### Additional Notes
i don't want the inner field as nilable, environment 1 has "C_GameRules" as global available and the function is guaranteed to be in there, environment 2 has the global set to nil
### Log File
_No response_
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用所示的 Lua 中繼檔宣告在 Visual Studio Code Extension 中重現該報告,並檢查 C_GameRules.IsHardcoreActive() 的型別檢查診斷。當選用的全域變數產生 nil 檢查警告,而其內部函式仍維持不可為 nil 時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100