lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Something not okay with enum types

Open d-enk opened this issue 1 year ago • 1 comments

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

---@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

---@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

d-enk avatar Oct 16 '23 13:10 d-enk

exactly my thoughts :| its not as useful if you can just make a typo / change values and not be warned about it

dganzella avatar Jan 27 '24 12:01 dganzella