LuaLS / LuaLS/lua-language-server

Ability to use specific enum keys as params

Open
#2,274 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

It would be nice to be able to use specific enum keys as params. For example today if you try to do something like this:

```
---@enum TestEnum
TestEnum = {
ONE = 1,
TWO = 2,
THREE = 3,
}

---@param test TestEnum.ONE
local function test(test)
end

test(TestEnum.ONE)
test(1)
```

You will get an error:
```
Cannot assign `integer` to parameter `TestEnum.ONE`.
- `integer` cannot match `TestEnum.ONE`
- Type `integer` cannot match `TestEnum.ONE`
- Type `number` cannot match `TestEnum.ONE`
```

Interestingly lls understands that TestEnum.ONE is a real thing just not that it is equal to TestEnum.ONE or 1. For exmaple if you try this:
```
---@enum TestEnum
TestEnum = {
ONE = 1,
TWO = 2,
THREE = 3,
}

---@param test TestEnum.One
local function test(test)
end

test(TestEnum.ONE)
test(1)
```
You will get an error:
```
---@param test TestEnum.NonEnumValue
```

Contributor guide

Open the contributing guide

Research direction

No file, test, or entry point is identified in the issue, so begin by locating enum type checking and parameter-assignability handling in lua-language-server. Done means TestEnum.ONE is accepted for TestEnum.ONE and its underlying value 1 is handled consistently, while invalid enum keys remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.