LuaLS / LuaLS/lua-language-server

False negative for param-type-mismatch when using a variable as argument

未關閉
#2,734 0 則留言 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

```lua
---@class (exact) Foo
---@field FooField integer
local Foo

---@param FooParam Foo
local function test(FooParam) end

local x = {z = 1}
test(x)

test({z = 1})
```

In the example above, Lua LS should report a param-type-mismatch diagnostic for `test(x)`. It has enough information to know that x cannot be of type Foo, at the very least because it is missing `FooField`.
We see that test({z=1}) correctly reports the param-type-mismatch diagnostic.

### Actual Behaviour

No error is reported.
![image](https://github.com/LuaLS/lua-language-server/assets/36710691/5bd6c68a-21ab-4235-b4e3-2f5c7f9a87de)

### Reproduction steps

In any editor with Lua LS installed, write the provided code. Observe that there are no squiggles reported.

### Additional Notes

I would say this is a pretty serious bug. I would have expected Lua LS's type checking to be robust enough to handle checking the types of variables. It seems that all it is doing is checking that the type is a table.

IS this because there is no narrowing of variables once they become tables? This is only done for table literals?

### Log File

_No response_

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 Lua LS 中提供的 Lua 重現開始,追蹤傳遞給 test 的參數之型別檢查路徑,將變數引數與表格字面值進行比較。當針對 test(x) 回報相同的 param-type-mismatch 診斷時即表示完成,包括缺少 FooField 的情況。

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

評估

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

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

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