LuaLS / LuaLS/lua-language-server

A key and value of the nested table are not defined

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

還沒有人認領這個 Issue。

bug feat/generic
主要語言
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?

Other

### Expected Behaviour


![image](https://user-images.githubusercontent.com/57856647/204633131-b651e904-c5dd-4d46-96dc-87f7033a3119.png)

![image](https://user-images.githubusercontent.com/57856647/204633153-d8209139-9ce7-4543-b1c4-37e37c1f536e.png)

![image](https://user-images.githubusercontent.com/57856647/204633184-cab71a17-2f75-44ac-95ba-98bab0877005.png)

### Actual Behaviour

![image](https://user-images.githubusercontent.com/57856647/204633081-2bd4dd79-cae1-4fdb-a78a-c5151897a76e.png)

![image](https://user-images.githubusercontent.com/57856647/204632236-1370ae1e-aa2c-4544-afc5-af330e117ae9.png)

![image](https://user-images.githubusercontent.com/57856647/204632254-2359446b-6365-4064-a1a1-e8c13ed90450.png)

### Reproduction steps

Maybe I'm doing something wrong, but it seems to have worked before

```lua
---@class Test
---@field ID integer
local Test = {};

---@param id integer
---@return Test
function Test:new(id)
return setmetatable({ ID = id }, { __index = self });
end

---@type table >
local tab = {
[1] = { 1.0, 2.1, 3.2 },
[2] = { 4.0, 5.1, 6.2 },
[3] = { 7.0, 8.1, 9.2 }
}

---@generic T
---@param test table
---@return table
local function convert2Test(test)
local t = {};
for k, v in pairs(test) do
t[Test:new(k)] = v;
end
return t;
end

local newTab = convert2Test(tab);

for k, v in pairs(newTab) do
print(k, v); -- ok! k and v detected
end

local test = Test:new(3);
local info = newTab[test];

if info then
for k, v in pairs(info) do
print(k, v); -- oops! k and v not detected
end
end
```

### Additional Notes

_No response_

### Log File

_No response_

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 issue 中的 Lua 重現開始,比較預期和實際螢幕擷取畫面中的推斷型別。調查用於 tab 的巢狀表格型別,以及透過 convert2Test 傳回的值。當內層表格的鍵型別和值型別在最終的 pairs 迴圈中被推斷出來時,即表示完成。

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

評估

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

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

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