LuaLS / LuaLS/lua-language-server

Something not okay with enum types

Open
#2,377 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Linux

### What is the issue affecting?

Type Checking

### Expected Behaviour

```lua
---@enum EnumAB
local e = {
A = 0,
B = 1,
}

---@type EnumAB
local a = 1

---@type EnumAB.A
local ea = e.A

---@type EnumAB.B
local eb = e.B

---@type EnumAB.B
local eb = e.A -- Cannot assign `EnumAB.A` to `EnumAB.B`

---@type EnumAB
local ee = eb

---@type EnumAB.A
local eea = ee -- Cannot assign `EnumAB` to `EnumAB.A`
```

### Actual Behaviour

```lua
---@enum EnumAB
local e = {
A = 0,
B = 1,
}

---@type EnumAB
local a = 1

---@type EnumAB.A
local ea = e.A -- Cannot assign `integer` to `EnumAB.A`

---@type EnumAB.B
local eb = e.B -- Cannot assign `integer` to `EnumAB.B`

---@type EnumAB.B
local eb = e.A -- Cannot assign `EnumAB.A` to `EnumAB.B`

---@type EnumAB
local ee = eb -- Cannot assign `EnumAB.B` to `EnumAB`.

---@type EnumAB.A
local eea = ee -- Cannot assign `EnumAB` to `EnumAB.A`
```

### Reproduction steps

-

### Additional Notes

`EnumAB.A` is most likely an unintended side effect, but having restrictions inside the enum seems like a good idea

### Log File

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file, entry point, or test is named. Reproduce the enum assignments from the issue in the Lua language server's Visual Studio Code extension on Linux, then trace the type-checking behavior and define regression coverage for the expected relationships between EnumAB, EnumAB.A, and EnumAB.B.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.