Skip to content

Something not okay with enum types #2377

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
d-enk opened this issue Oct 16, 2023 · 1 comment
Open

Something not okay with enum types #2377

d-enk opened this issue Oct 16, 2023 · 1 comment

Comments

@d-enk
Copy link
Contributor

d-enk commented Oct 16, 2023

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 d-enk mentioned this issue Jan 9, 2024
@dganzella
Copy link

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants