LuaLS / LuaLS/lua-language-server

A union type should not merge class fields

Đang mở
#3,410 1 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?

MacOS

What is the issue affecting?

Annotations

Expected Behaviour
---@class (exact) TypeA
---@field type 'A'
---@field commonField number
---@field specificFieldA number

---@class (exact) TypeB
---@field type 'B'
---@field commonField string
---@field specificFieldB string

---@alias Type_Either_A_Or_B_But_Not_Both TypeA|TypeB

---@type Type_Either_A_Or_B_But_Not_Both
local testA = {
    type = 'A', --- Indicates that this should be of TypeA
    commonField = 'test', --- Should be an error. TypeA.commonField should be a number
    specificFieldA = 123, --- OK
    specificFieldB = 'Hello' --- Should be an error. TypeA.specificFieldB doesn't exist
}

---@type Type_Either_A_Or_B_But_Not_Both
local testB = {
    type = 'B', --- Indicates that this should be of TypeB
    commonField = 'test', --- OK
    specificFieldA = 123, --- Should be an error. TypeB.specificFieldA doesn't exist
    specificFieldB = 'Hello' --- OK
}
Actual Behaviour

TypeA|TypeB is merged, so none of the mismatched fields/types are reported as errors.

local testA: TypeA|TypeB {
    commonField: string|number,
    specificFieldA: number,
    specificFieldB: string,
    type: 'A'|'B',
}
Reproduction steps

Paste the code 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 ví dụ TypeA|TypeB có chú thích trong tiện ích mở rộng Visual Studio Code, sau đó lần theo cách language server hợp nhất các trường của union class. Hoàn tất khi discriminator chọn đúng class và báo cáo commonField không khớp cùng các trường riêng của từng member được thể hiện trong ví dụ.

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
tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/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.