LuaLS / LuaLS/lua-language-server
Enum type is lost when given as union
未关闭
还没有人认领这个 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 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.
[{
"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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 issue 中的 Lua 示例在 Visual Studio Code 中复现该诊断,然后检查针对 generated/library.lua 报告的类型检查路径。当 CMD.REPAIR 和其他枚举成员能够作为文档所述 union 的参数被接受,且没有 param-type-mismatch 诊断时,此更改即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100