lua-language-server
                                
                                 lua-language-server copied to clipboard
                                
                                    lua-language-server copied to clipboard
                            
                            
                            
                        Error returning derived classes
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