Table type annotations
還沒有人認領這個 Issue。
評估
研究方向
使用提供的 Lua 範例重現該報告,並檢查 language server 的 generic-table 型別檢查進入點。驗證指派和方法引數是否同時驗證鍵的型別和值的型別,然後新增或更新涵蓋範圍,使不相容的表格內容產生診斷,同時繼續接受有效的表格。
由索引模型根據 Issue 內容生成。
描述
Hello everyone.
I've defined a field as table<MyStates, BaseState>, but the analyzer doesn't complain when I assign a table with a completely different structure to it.
---@class BaseState
local BaseState = {}
---@enum MyStates
local States = {
GAME = 1,
GAME_OVER = 2,
}
---@class MyStateMachine
---@field private _states table<MyStates, BaseState>
local MyStateMachine = {}
MyStateMachine.__index = MyStateMachine
---@param states table<MyStates, BaseState>
function MyStateMachine:setStates(states)
self._states = states
end
function tmp()
-- Assigning a table with a different annotation directly. The analyzer doesn't complain.
MyStateMachine._states = {
['kek'] = 69
}
-- Passing a table with a different annotation to a method. The analyzer doesn't complain.
MyStateMachine:setStates({
['kek'] = 69,
})
-- The analyzer correctly complains about a number assignment.
-- MyStateMachine._states = 69
-- The analyzer correctly complains about passing a number.
-- MyStateMachine:setStates(2)
end
As you can see, the type checker only seems to validate that the value is a table, but doesn't validate the internal key and value types for table<MyStates, BaseState>. Is this the expected behavior, or am I missing something? Is there a way to enforce stricter type checking for the contents of generic tables?
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- 平均合併
- 8 天 9 小時
- 30 天內合併 PR
- 1
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
LuaLS/lua-language-server 的其他 Issue
-
enhancement
難度 2/5 1-3 小時 新手友好度 62/100
LuaLS/lua-language-server#1776 ·
-
難度 3/5 1-2 天 新手友好度 65/100
LuaLS/lua-language-server#3463 · 5 則留言 ·
-
難度 4/5 3-5 天 新手友好度 55/100
LuaLS/lua-language-server#3461 ·
-
難度 3/5 1-2 天 新手友好度 68/100
LuaLS/lua-language-server#3460 · 1 則留言 · 1 個 reaction ·
-
難度 3/5 1-2 天 新手友好度 68/100
LuaLS/lua-language-server#3459 · 1 個 reaction ·
查看 LuaLS/lua-language-server 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 70/100
openSUSE/python-rpm-macros#219 ·
-
bug mini.bracketed
難度 2/5 1-3 小時 新手友好度 75/100
-
accessibility bug typst
難度 2/5 1-3 小時 新手友好度 75/100
quarto-dev/quarto-cli#14947 · 2 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
HenrikBengtsson/CBI-software#134 ·
-
Nmap
難度 1/5 1 小時以內 新手友好度 85/100