LuaLS / LuaLS/lua-language-server

`generic` inheritance does not work

Đang mở
#1,272 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.

enhancement feat/generic feat/LuaCats Annotations
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,

image

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

image

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

image

and there is no error either

image

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

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

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.