LuaLS / LuaLS/lua-language-server
Missing diagnostic when calling a non-function value
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
### 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_
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用呼叫數值和字串值的 Lua 程式碼片段重現此問題,然後追蹤處理呼叫運算式的診斷或型別檢查進入點。完成標準是:對於明確不可呼叫的值回報診斷,同時仍接受可呼叫的表格以及具有明確 overload 或 __call 簽章的值。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 65/100