LuaLS / LuaLS/lua-language-server
Error returning derived classes
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
What is the issue affecting?
Annotations
Expected Behaviour
---@class Thing
---@field getCreature fun(self:Thing):Creature?
---@field getPlayer fun(self:Thing):Player?
---@field getMonster fun(self:Thing):Monster?
---@field getNpc fun(self:Thing):Npc?
---@class Creature:Thing
---@field getCreature fun(self:Creature):Creature
---@field getPlayer fun(self:Creature):Player?
---@field getMonster fun(self:Creature):Monster?
---@class Player:Creature
---@field getPlayer fun(self:Player):Player
---@field getMonster fun(self:Player):nil
---@field getNpc fun(self:Player):nil
---@class Monster:Creature
---@field getPlayer fun(self:Monster):nil
---@field getMonster fun(self:Monster):Monster
---@field getNpc fun(self:Monster):nil
function Creature:getCreature() return self end
function Creature:getPlayer() return self:isPlayer() and self or nil end
function Creature:getMonster() return self:isMonster() and self or nil end
function Creature:getNpc() return self:isNpc() and self or nil end
Actual Behaviour
The current behavior is that the methods: getMonster, getNpc throw the following error:
Annotations specify that return value #1 has a type of `Monster?`, returning value of type `Creature|nil` here instead.
- `Creature` cannot match `Monster?`
- Type `Creature` cannot match `nil`
- Type `Thing` cannot match `nil`
- Type `Creature` cannot match `Monster`
- Type `Thing` cannot match `Monster`Lua Diagnostics.(return-type-mismatch)
The error does not occur with the Player class which is also derived from the Creature class
Reproduction steps
- Use the code of the expected behavior
Additional Notes
No response
Log File
No response
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 chẩn đoán trong Visual Studio Code với đoạn mã Lua từ issue, tập trung vào các chú thích giá trị trả về của lớp dẫn xuất cho getMonster và getNpc. Theo dõi hành vi chú thích và kiểm tra kiểu chịu trách nhiệm cho sự không khớp; hoàn thành có nghĩa là bản tái hiện không còn báo lỗi kiểu trả về không chính xác, đồng thời vẫn giữ nguyên hành vi đã được báo cáo cho Player.
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