LuaLS / LuaLS/lua-language-server
Error returning derived classes
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Lua
- Estrellas
- 4.4k
- Forks
- 442
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza reproduciendo el diagnóstico en Visual Studio Code con el fragmento de Lua del issue, centrándote en las anotaciones de retorno de las clases derivadas para getMonster y getNpc. Rastrea el comportamiento de las anotaciones y de la comprobación de tipos responsable de la discrepancia; se considera terminado cuando la reproducción ya no informe de un error incorrecto de tipo de retorno y preserve el comportamiento indicado para Player.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- lua
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100