Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Feature Request: ability to overload the return value type

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

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
45/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Pouca atividade
Stack de tecnologia
lua
Domínio
devtools

Direção de pesquisa

Comece rastreando como o servidor de linguagem representa múltiplos valores de retorno anotados e os verifica nos locais de chamada. Use o exemplo de ECS na issue como o comportamento a ser investigado, incluindo os casos de zero e dois valores. Está concluído quando uma anotação compatível puder expressar retornos multivalor all-or-nothing ou unidos sem exigir o cast mostrado, e os diagnósticos estiverem cobertos para ambos os casos.

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

Descrição

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

macOS

What is the issue affecting?

Annotations

Feature request

In my game's ECS bindings I have getter functions that work like this:

---@param id integer
---@return number? inv_mass
---@return number? restitution
function ecs.get_collision_body_values(id) end

local inv_mass, restitution = ecs.get_collision_body_values(entity_id)

This calls into a native ECS implementation that either pushes the 2 return values and returns with return 2; (2 return values) or if the return values doesn't exist, push nothing and return 0; (zero return values).

This can be used in my game code like this:

local function debug_body(id)
      local inv_mass, restitution = ecs.get_collision_body_values(id)
      if inv_mass == nil then -- collision_body component not set, do nothing
          return
      end
      ---@cast restitution number
      -- ^^ have to cast restitution number? -> number to avoid warning
      print(inv_mass, restitution)
end

Would be nice if there was a way to annotate an "all or nothing" multiple return value type. E.g., a function will either return multiple return values (e.g., not number? but number) or that it will return nothing. Or I guess more generally, the ability to somehow specify a union of different multivalue return types.

FWIW, it'd be possible to return "a bunch of values" or "nothing" by using a table? return type. However, I'm trying very hard not to allocate tables in my hot game's hot paths, thus I favor concrete types and multiple return.

Linguagem predominante
Lua
Estrelas
4.4k
Forks
446
Merge médio
8d 9h
PRs com merge (30d)
1

Preparar o ambiente

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.

Mais de LuaLS/lua-language-server

Todas as issues de LuaLS/lua-language-server

Issues semelhantes

Mais issues de Lua

Receba novas issues na sua caixa de entrada

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