LuaLS / LuaLS/lua-language-server
Enum type is lost when given as union
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?
Windows WSL
What is the issue affecting?
Type Checking
Expected Behaviour
A parameter of union of enum entries should accept those entries.
Actual Behaviour
---Command constants.
---
---@enum CMD
CMD = {
---@type 40
REPAIR = nil,
---@type 90
RECLAIM = nil,
---@type 110
RESTORE = nil,
---@type 125
RESURRECT = nil,
---@type 130
CAPTURE = nil,
}
---Called when a construction unit wants to "use his nano beams".
---
---@param unitID integer
---@param unitDefID integer
---@param action
--- | -1 # Build
--- | CMD.REPAIR # Repair
--- | CMD.RECLAIM # Reclaim
--- | CMD.RESTORE # Restore
--- | CMD.RESURRECT # Resurrect
--- | CMD.CAPTURE # Capture
---@return boolean actionAllowed
function SyncedCallins:AllowBuilderHoldFire(unitID, unitDefID, action) end
local x = nil ---@type SyncedCallins
local y = x:AllowBuilderHoldFire(5, 3, CMD.REPAIR)
The enum type is being resolved to 40 and losing information about it being an enum.
[{
"resource": "/home/rhys/spring/rts/Lua/library/generated/library.lua",
"owner": "_generated_diagnostic_collection_name_#1",
"code": "param-type-mismatch",
"severity": 4,
"message": "Cannot assign `40` to parameter `-1|CMD.CAPTURE|CMD.RECLAIM|CMD.REPAIR|CMD.RESTORE...(+1)`.\n- `40` cannot match `-1|CMD.CAPTURE|CMD.RECLAIM|CMD.REPAIR|CMD.RESTORE...(+1)`\n- `40` cannot match any subtypes in `-1|CMD.CAPTURE|CMD.RECLAIM|CMD.REPAIR|CMD.RESTORE...(+1)`\n- Type `40` cannot match `CMD.CAPTURE`\n- Type `number` cannot match `CMD.CAPTURE`\n- Type `40` cannot match `CMD.RESURRECT`\n- Type `number` cannot match `CMD.RESURRECT`\n- Type `40` cannot match `CMD.RESTORE`\n- Type `number` cannot match `CMD.RESTORE`\n- Type `40` cannot match `CMD.RECLAIM`\n- Type `number` cannot match `CMD.RECLAIM`\n- Type `40` cannot match `CMD.REPAIR`\n- Type `number` cannot match `CMD.REPAIR`\n- Literal `40` cannot match integer `-1`",
"source": "Lua Diagnostics.",
"startLineNumber": 3090,
"startColumn": 40,
"endLineNumber": 3090,
"endColumn": 50
}]
Reproduction steps
Paste code example above into VSCode.
Additional Notes
No response
Log File
No response
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
Reproduce the diagnostic in Visual Studio Code using the Lua example in the issue, then inspect the reported type-checking path for generated/library.lua. The change is complete when CMD.REPAIR and the other enum members are accepted as arguments to the documented union without a param-type-mismatch diagnostic.
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
- 45/100