LuaLS / LuaLS/lua-language-server

---@class with function return question

Aberta
#2,602 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

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

Descrição

so I have this (as a mockup):
```lua
do
---@class a
local a = {}

---@generic T
---@param self a
---@param new T
---@return T
a.extend = function(self, new)
--...
return new
end
end
```
and it's supposed to be inheritance for prototypes, right, but I'm trying to make the LS think that it returns the second parameter `new` and it does that and the LS thinks that, so far so good. So this
```lua
local b = a:extend{
n = 1
}
```
will make it like this:
![p1](https://github.com/LuaLS/lua-language-server/assets/50140319/ae40c16c-62bd-4429-8c40-1c2d5190d446)
but the problem is, that if I use `---@class b` here, then it will ignore what the function returns and I get this:
![p2](https://github.com/LuaLS/lua-language-server/assets/50140319/b0535d12-35f5-49cc-8088-2ae955b32f4a)
am I missing something or is it just not possible? Though, if I separate it into two statements like this,
```lua
---@class b
local b = {
n = 1
}

b = a:extend(b)
```
then I get what I want:
![p3](https://github.com/LuaLS/lua-language-server/assets/50140319/d56f304d-8fef-46c6-baa8-45491c2829d2)
but it's not ideal, since it's two statements now and I can't use the `fun{}` syntactic sugar this way, which would be the whole reason, right. Is there a way to make it work? Also I'm unsure about how to properly word the title here

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 é mencionado. Reproduza os dois trechos de Lua de uma linha e os dois de duas instruções e, em seguida, rastreie a inferência de tipos do LuaLS para declarações locais, anotações de classe, genéricos e valores de retorno de funções. Considera-se concluído quando o comportamento compatível estiver implementado e coberto por um teste de regressão, ou quando a limitação estiver claramente documentada.

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.