LuaLS / LuaLS/lua-language-server

Enum type is lost when given as union

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

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

主要言語
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 WSL

What is the issue affecting?

Type Checking

Expected Behaviour

A parameter of union of enum entries should accept those entries.

Actual Behaviour
---Command constants.
---
---@enum CMD
CMD = {
	---@type 40
	REPAIR = nil,

	---@type 90
	RECLAIM = nil,

	---@type 110
	RESTORE = nil,

	---@type 125
	RESURRECT = nil,

	---@type 130
	CAPTURE = nil,
}

---Called when a construction unit wants to "use his nano beams".
---
---@param unitID integer
---@param unitDefID integer
---@param action
---  | -1 # Build
---  | CMD.REPAIR # Repair
---  | CMD.RECLAIM # Reclaim
---  | CMD.RESTORE # Restore
---  | CMD.RESURRECT # Resurrect
---  | CMD.CAPTURE # Capture
---@return boolean actionAllowed
function SyncedCallins:AllowBuilderHoldFire(unitID, unitDefID, action) end

local x = nil ---@type SyncedCallins
local y = x:AllowBuilderHoldFire(5, 3, CMD.REPAIR)

The enum type is being resolved to 40 and losing information about it being an enum.

Image

[{
	"resource": "/home/rhys/spring/rts/Lua/library/generated/library.lua",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "param-type-mismatch",
	"severity": 4,
	"message": "Cannot assign `40` to parameter `-1|CMD.CAPTURE|CMD.RECLAIM|CMD.REPAIR|CMD.RESTORE...(+1)`.\n- `40` cannot match `-1|CMD.CAPTURE|CMD.RECLAIM|CMD.REPAIR|CMD.RESTORE...(+1)`\n- `40` cannot match any subtypes in `-1|CMD.CAPTURE|CMD.RECLAIM|CMD.REPAIR|CMD.RESTORE...(+1)`\n- Type `40` cannot match `CMD.CAPTURE`\n- Type `number` cannot match `CMD.CAPTURE`\n- Type `40` cannot match `CMD.RESURRECT`\n- Type `number` cannot match `CMD.RESURRECT`\n- Type `40` cannot match `CMD.RESTORE`\n- Type `number` cannot match `CMD.RESTORE`\n- Type `40` cannot match `CMD.RECLAIM`\n- Type `number` cannot match `CMD.RECLAIM`\n- Type `40` cannot match `CMD.REPAIR`\n- Type `number` cannot match `CMD.REPAIR`\n- Literal `40` cannot match integer `-1`",
	"source": "Lua Diagnostics.",
	"startLineNumber": 3090,
	"startColumn": 40,
	"endLineNumber": 3090,
	"endColumn": 50
}]
Reproduction steps

Paste code example above into VSCode.

Additional Notes

No response

Log File

No response

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

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

はじめの一歩

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

調査の方向性

Issue の Lua 例を使用して Visual Studio Code で診断を再現し、続いて generated/library.lua に対して報告された型チェックの経路を調査します。CMD.REPAIR とその他の enum メンバーが、param-type-mismatch 診断なしで、ドキュメント化された union の引数として受け入れられれば、変更は完了です。

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

評価

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

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

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