LuaLS / LuaLS/lua-language-server
No Protection on enum values as function input
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
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")`
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the provided enum and function example as the reproduction, comparing diagnostics for TestEnum.FOUR and "FOUR". Trace the language server's enum and function-argument type checking, then add coverage for both calls; done when the invalid enum member is diagnosed consistently with the invalid string literal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100