LuaLS / LuaLS/lua-language-server
`generic` inheritance does not work
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ả
The second case
Core = {};
---@class Rotation
---@field Enabled boolean
local Rotation = {}
function Rotation:OnLoad() end
function Rotation:OnUnload() end
---@class RotationEngine
Core.RotationEngine = {}
---@generic T
---@param name `T`
---@return T|Rotation rotation
function Core.RotationEngine.AddRotation(name) end
---@class MyRotation
---@field testfield table
local MyRotation = {};
function MyRotation:Test() end
local rotation = Core.RotationEngine.AddRotation("MyRotation");
---@param self MyRotation
---@return boolean
local function myFunc(self) end
local a = myFunc(rotation);
In the first case, in the MyRotation class, we seek methods of the Rotation class,

but also an error Cannot assign MyRotation|Rotation to parameter MyRotation.Lua Diagnostics.(param-type-mismatch)

The second case
Core = {};
---@class Rotation
---@field Enabled boolean
local Rotation = {}
function Rotation:OnLoad() end
function Rotation:OnUnload() end
---@class RotationEngine
Core.RotationEngine = {}
---@generic T: Rotation
---@param name `T`
---@return T rotation
function Core.RotationEngine.AddRotation(name) end
---@class MyRotation
---@field testfield table
local MyRotation = {};
function MyRotation:Test() end
local rotation = Core.RotationEngine.AddRotation("MyRotation");
---@param self MyRotation
---@return boolean
local function myFunc(self) end
local a = myFunc(rotation);
In the second case there is no inheritance

and there is no error either

Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện cả hai đoạn mã Lua từ issue và so sánh kiểu được suy luận của rotation, tính năng hoàn tất phương thức và các chẩn đoán. Theo dõi quá trình suy luận kiểu trả về generic và cách xử lý kế thừa lớp liên quan đến AddRotation. Được xem là hoàn tất khi các member được kế thừa như dự kiến có thể sử dụng được và sự không khớp kiểu MyRotation|Rotation không chính xác được giải quyết mà không làm mất hành vi của trường hợp thứ hai.
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
- 35/100