Skip to content

Enum type is lost when given as union #3104

Open
@rhys-vdw

Description

@rhys-vdw

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.

Image

[{
	"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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions