LuaLS / LuaLS/lua-language-server

Invalid type diagnostic doesn't show when passing value from array directly to a function

Open
#1,643 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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?

Other

Which OS are you using?

Linux

What is the issue affecting?

Type Checking, Diagnostics/Syntax Checking

Expected Behaviour

When using a value from an array as a parameter I expect type checking to work.

Actual Behaviour

Type checking only works when I assign the value from the array to a temporary variable, not when passing it to a function directly.

Reproduction steps

This doesn't show a warning:

---@param num integer
function receive(num)
end

---@type (integer?)[]
local values = {}

receive(values[1])

This works:

local value = values[1]
receive(value) -- Cannot assign `integer?` to parameter `integer`.
Additional Notes

No response

Log File

No response

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

No source file or test is named. Start by reproducing the two Lua snippets and tracing the type-checking diagnostic path for a direct array-index argument versus a temporary variable; done means the direct call reports the same integer? to integer mismatch.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.