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

False-positive type error: `vim.cmd` callable table flagged as "table cannot match fun(...)"

Aberta
#3,272 0 comentários 1 reação 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

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

Direção de pesquisa

Comece reproduzindo o diagnóstico com pcall(vim.cmd, "redrawtabline") em um buffer Lua do Neovim e, em seguida, rastreie os diagnósticos do LuaLS e a inferência de tipos para tabelas chamáveis com metamétodos __call. Está concluído quando tabelas chamáveis são aceitas onde valores de função são esperados sem ocultar erros de tipo genuínos, e a reprodução informada não produz mais um diagnóstico.

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

Descrição

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

lua-language-server should recognize callable tables (with a __call metamethod) as valid function values. Passing Neovim’s vim.cmd to pcall should not raise a type error.

Actual Behaviour

lua-language-server reports a false-positive type error when vim.cmd (a callable table in Neovim) is passed to pcall:

Cannot assign table to parameter fun(...):...unknown
Type table cannot match fun(...):...unknown

Reproduction steps
  1. In Neovim, open a Lua buffer (e.g., :new | set ft=lua).

  2. Insert the following code:

    -- Works at runtime, but LuaLS flags the next line:
    pcall(vim.cmd, "redrawtabline")
    -- Diagnostic shown by LuaLS:
    -- Cannot assign `table` to parameter `fun(...):...unknown`
    
  3. Observe the diagnostic from lua-language-server.

  4. Execute the code in Neovim (e.g., :luafile %) to confirm it runs without runtime errors.

Additional Notes
  • vim.cmd is a callable table provided by Neovim (implemented via __call metamethod). Direct calls like vim.cmd("redrawtabline") work at runtime. The false-positive only appears when passing vim.cmd as a function value (e.g., to pcall).

  • Workarounds:

    -- Wrap in a function
    pcall(function() vim.cmd("redrawtabline") end)
    
    -- or use the typed API
    pcall(vim.api.nvim_cmd, { cmd = "redrawtabline" }, {})
    
  • Please treat callable tables as functions for the purpose of type checking / inference.

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

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.

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.