Table type annotations
まだ誰も着手していません。
評価
調査の方向性
提供された 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時間
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
LuaLS/lua-language-server#3459 · リアクション 1 件 ·
LuaLS/lua-language-server の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
HenrikBengtsson/CBI-software#134 ·
-
Nmap
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
secondlife/slua#96 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100