LuaLS / LuaLS/lua-language-server

Missing diagnostic when calling a non-function value

Open
#3,411 0 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?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Windows

### What is the issue affecting?

Diagnostics/Syntax Checking

### Expected Behaviour

LuaLS should report a diagnostic when a value whose type is known to be non-callable is called like a function.

For example, calling a `number`, `string`, `boolean`, or a plain table without a known `__call` / `@overload` signature should produce a warning/error, because the code will fail at runtime.

### Actual Behaviour

No diagnostic is reported.

Even when the value is explicitly annotated or cast as `number`, LuaLS accepts the call silently.

### Reproduction steps

Use the following code:
```lua
local x = 1 --[[@as number]]
x()

local y = 1
y()

---@type number
local z = 1
z()
```

Expected: diagnostics on x(), y(), and z().
Actual: no diagnostics are reported.
At runtime, these calls fail with an error similar to:
attempt to call a number value

### Additional Notes

This is different from callable table / __call support.
I am not asking LuaLS to reject values that are explicitly annotated as callable, for example with ---@overload fun(...) or an equivalent __call signature.
The issue is about direct calls to values whose inferred or declared type is definitely not callable, such as number.
This also affects typo detection. For example, code like this can accidentally parse as a function call:
```lua
---@param name string
local function greet(name)
return "Hello " .. name "!"
end
```
Here name "!" is a call expression, but name is a string, so a diagnostic would be useful.

### 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

Reproduce the issue with the Lua snippets calling number and string values, then trace the diagnostics or type-checking entry point that handles call expressions. Done means diagnostics are reported for definitely non-callable values while callable tables and values with explicit overload or __call signatures remain accepted.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.