LuaLS / LuaLS/lua-language-server

Union table|class doesn't accept a generic table and only accepts a class instance (causing false missing-fields diagnostic)

未關閉
#2,606 3 則留言 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, Diagnostics/Syntax Checking

Expected Behaviour

When a function is declared as accepting both table and a custom class type, it should accept getting passed a generic table.

Actual Behaviour

LLS insists on a table matching the class being passed (with all the fields set) and reports the missing-fields diagnostic when passing a generic table.

Reproduction steps

LLS definition file contains the following:

---@meta

---@class TestClass
---@field TestField number A test field in test class
TestClass = {}

-- TestFunction1
---@param generic_table_or_testclass_instance table|TestClass
function TestFunction1(generic_table_or_testclass_instance) end

-- TestFunction2
---@param generic_table table
---@param testclass_instance TestClass
---@overload fun(generic_table: table)
---@overload fun(testclass_instance: TestClass)
function TestFunction2(generic_table, testclass_instance) end

-- TestFunction3
---@param generic_table table
function TestFunction3(generic_table) end

-- TestFunction3
---@param testclass_instance TestClass
function TestFunction3(testclass_instance) end

And then a lua code file contains a call to either test function like

TestFunction1({1,2,3})
TestFunction2({1,2,3})
TestFunction3({1,2,3})

LLS reports Missing required fields in type ``TestClass``: ``TestField`` Lua Diagnostics.(missing-fields) for all 3 calls. Instead it should accept the table as input parameter for the 3 functions.

Additional Notes

No response

Log File

No response

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

先從重現程式碼中的 Lua 和型別註解著手,接著追蹤為 union 和 overload 參數產生缺少欄位診斷的型別檢查路徑。完成的標準是:三次呼叫中的泛型表格都能被接受,且不會回報缺少 TestClass.TestField;issue 中沒有指明原始碼檔案或測試。

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

評估

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

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

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