LuaLS / LuaLS/lua-language-server

`generic` inheritance does not work

Abierto
#1,272 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement feat/generic feat/LuaCats Annotations
Lenguaje dominante
Lua
Estrellas
4.4k
Forks
442
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza reproduciendo ambos fragmentos de Lua del issue y compara el tipo inferido de rotation, la finalización de métodos y los diagnósticos. Sigue la inferencia del tipo de retorno genérico y el manejo de la herencia de clases implicados en AddRotation. Se considera completado cuando los miembros heredados previstos están disponibles y se resuelve la discrepancia de tipos incorrecta MyRotation|Rotation sin perder el comportamiento del segundo caso.

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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.