LuaLS / LuaLS/lua-language-server

Problem with generics

Aberta
#911 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

enhancement feat/generic
Linguagem predominante
Lua
Estrelas
4.4k
Forks
442
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

I have reported a similar problem before and I understand that it is not simple, but if you solve it, I will be crazy happy!

I'm working on an OOP library and here's a truncated example of the constructor it uses:

---@generic T
---@param t1 T
---@param t2 T
---@return T
function new(t1, t2) end

The first table here is the class from which the instance will inherit, and the second is the additional settings that will be substituted to the instance. So all tables has the same type.

When I call this constructor, the generics work almost correctly - the result of this function has the same type as any argument:

---@class Example1
---@field e1a string
---@field e1b string
local Example1 = {}

---@class Example2
---@field e2a string
---@field e2b string
local Example2 = {}

local e = new(Example1, {}) -- e is Example1
local e = new(Example2, {}) -- e is Example2
local e = new({}, Example1) -- e is Example1
local e = new({}, Example2) -- e is Example2

But the problem is that when I start typing a text between the curly braces in the example above, I get no hints about the class fields. Maybe I'm describing generics wrong? Do you have any idea? Thanks!

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Nenhum arquivo-fonte ou teste é especificado. Reproduza o exemplo de construtor genérico no Lua language server e inspecione como a conclusão é inferida dentro dos argumentos de tabela vazios quando o primeiro argumento é Example1 ou Example2. O trabalho estará concluído quando os campos relevantes da classe forem sugeridos nesses literais de tabela, preservando o tipo de resultado inferido existente.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
lua
Domínio
devtools
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.