LuaLS / LuaLS/lua-language-server

string|nil passed to string parameter not flagged as error with strict settings

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

還沒有人認領這個 Issue。

主要語言
Lua
星號
4.4k
分支
442
PR 合併指標
30 天內沒有已合併 PR

描述

### How are you using the lua-language-server?

Command Line

### Which OS are you using?

Linux

### What is the issue affecting?

Type Checking

### Expected Behaviour

With the following config (see below), I expect Lua Language Server to report a type mismatch when passing a `string|nil` value to a function that expects a non-optional string parameter.

Specifically, this line should raise a diagnostic:

```
test_func(params.ip) -- where params.ip is string|nil, but test_func expects string
```

### Actual Behaviour

No error is reported by LLS, neither in VS Code nor when using the CLI with `--check`.

### Reproduction steps

1. Save this code in a `.lua` file:

```
---@class TestParams
---@field ip string | nil

---@param ip string
---@return string
local function test_func(ip)
return ip
end

---@type TestParams
local params = { ip = nil }

test_func(params.ip)

```

2. Use the following `lua-language-server config` (`.luarc.json` or through your client):

```
{
"runtime": {
"version": "Lua 5.1"
},
"diagnostics": {
"enable": true,
"disable": [],
"groupFileStatus": {
"ambiguity": "Any",
"await": "Any",
"codestyle": "Any",
"duplicate": "Any",
"global": "Any",
"luadoc": "Any",
"redefined": "Any",
"strict": "Any",
"strong": "Any",
"type-check": "Any",
"unbalanced": "Any",
"unused": "Any"
},
"groupSeverity": {
"ambiguity": "Error",
"await": "Error",
"codestyle": "Error",
"duplicate": "Error",
"global": "Error",
"luadoc": "Error",
"redefined": "Error",
"strict": "Error",
"strong": "Error",
"type-check": "Error",
"unbalanced": "Error",
"unused": "Error"
}
},
"type": {
"weakNilCheck": false
}
}
```

3. Run the CLI:

```
lua-language-server-3.15.0-linux-x64/bin/lua-language-server --check your_file.lua
```

Or use VS Code extension.

### Additional Notes

_No response_

### Log File

```
Diagnosis completed, no problems found
```

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從提供的 Lua 重現程式碼和 `.luarc.json` 開始,然後執行文件中記載的 `lua-language-server --check` 命令,以確認缺少該診斷。追蹤函式引數的型別檢查路徑並新增回歸涵蓋;完成的標準是將引數 `string|nil` 回報為與必要的 `string` 參數不相容。

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

評估

技術堆疊
lua
領域
tooling
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
38/100

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

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