LuaLS / LuaLS/lua-language-server

Enum type is lost when given as union

Đang mở
#3,104 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Lua
Star
4.4k
Fork
442
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện chẩn đoán trong Visual Studio Code bằng ví dụ Lua trong issue, sau đó kiểm tra đường dẫn kiểm tra kiểu được báo cáo cho generated/library.lua. Thay đổi được hoàn tất khi CMD.REPAIR và các thành viên enum khác được chấp nhận làm đối số cho union được ghi trong tài liệu mà không có chẩn đoán param-type-mismatch.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
lua
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.