LuaLS / LuaLS/lua-language-server

Table type annotations

オープン
#3,295 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Lua
スター
4.4k
フォーク
442
PR マージ指標
30日以内にマージされた PR はありません

説明

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?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された Lua の例で報告を再現し、language server の generic-table 型チェックのエントリポイントを調べてください。代入とメソッド引数の両方でキーの型と値の型が検証されることを確認し、互換性のないテーブル内容では診断が生成され、有効なテーブルは引き続き受け入れられるように、カバレッジを追加または更新してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。