LuaLS / LuaLS/lua-language-server
Index an enum-value table bug
未关闭
还没有人认领这个 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
What is the issue affecting?
Type Checking
Expected Behaviour
expected the value type of mapping when index
Actual Behaviour
got an unknown
Reproduction steps
---@enum(key) AttrName
local o = {
['hp_max'] = true,
}
local map = {
['hp_max'] = 114514,
}
---@param t table<AttrName, number>
local function test(t)
--[[
Usage 1: correct
]]
local a = 'hp_max'
local b = t[a] -- expected: number, got: number
print(b)
--[[
Usage 2: incorrect
]]
local c = t['hp_max'] -- expected: number, got: unknown
print(c)
--[[
Usage 3: correct
]]
local d = "hp_grow"
local e = t[d] -- expected: unknown, got: unknown
print(e)
end
test(map)
Additional Notes
No response
Log File
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
在 Windows 上使用提供的 Lua 代码片段,在 LuaLS Visual Studio Code 扩展中重现该报告,并检查使用 enum 键进行表索引的类型检查路径。比较三种用法的诊断结果,尤其是字面量索引 'hp_max'。当报告的类型与复现中的预期一致时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- compilers, devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100