LuaLS / LuaLS/lua-language-server

False negative: Warnings missing for table length mismatch

Open
#2,980 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Type Checking, Diagnostics/Syntax Checking

Expected Behaviour

In the reproduction code below, f({0}) and f({0, 0, 0}) should issue warnings because they do not match the annotation [integer, integer], which requires a two-element table (tuple).

Actual Behaviour

There are no warnings issued for tables that have an invalid length.

I can see other warnings (e.g., for f("string")), so Neovim and other diagnostics are working correctly.
Screenshot

Reproduction steps

Open a text editor with lua-ls enabled and copy/paste this code.

---@alias Cursor [integer, integer]

---@param c Cursor
local function f(c) end

f("string")

f({ 0 })
f({ 0, 0, 0 })
Additional Notes

I tested with lua-language-server 3.9.1 and 3.13.2 and both have this problem.

Log File

I checked ~/.local/state/nvim/lsp.log since :LspInfo indicates it is the log file, but it was empty.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction snippet and the lua-language-server type-checking and diagnostics path for table aliases. Compare the existing warning for f("string") with the missing warnings for f({ 0 }) and f({ 0, 0, 0 }). Done means tuple annotations report a diagnostic when the table length differs from the required two elements.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.