LuaLS / LuaLS/lua-language-server

No Protection on enum values as function input

未关闭
#2,384 2 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

Currently with code like the following:

---@enum TestEnum
TestEnum = {
	ONE = "ONE",
	TWO = "TWO",
	THREE = "THREE",
}

---@param test_enum TestEnum
local function test(test_enum)
	print(test_enum)
end

test(TestEnum.ONE) --- CORRECT: No error
test("ONE") --- CORRECT: No error
test(TestEnum.FOUR) --- INCORRECT: No error
test("FOUR") --- CORRECT: Error

There is no intellisense error for test(TestEnum.FOUR) like there is for test("FOUR")

Screenshot_1

It would be nice to get an error if you are trying to use a non-existing enum value (I have run into problems relating to this 😞) similarly if you are trying to use a string literal which doesn't match the enum.

I think this might be related to a wider issue where inputs to functions can be of type unknown even with the no-unknown setting.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用提供的 enum 和函数示例作为复现,比较 TestEnum.FOUR 和 "FOUR" 的诊断结果。跟踪 language server 对 enum 和函数参数的类型检查,然后为两次调用添加覆盖;当无效的 enum 成员与无效的字符串字面量得到一致诊断时即可完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
devtools
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。