LuaLS / LuaLS/lua-language-server

Missing diagnostic when calling a non-function value

Offen
#3,411 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Lua
Sterne
4.4k
Forks
442
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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:

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:

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das Problem mit den Lua-Snippets, die numerische und String-Werte aufrufen, und verfolge dann den Einstiegspunkt für Diagnosen oder die Typprüfung, der Call-Ausdrücke verarbeitet. Fertig ist die Aufgabe, wenn Diagnosen für eindeutig nicht aufrufbare Werte gemeldet werden, während aufrufbare Tabellen und Werte mit expliziten Overload- oder __call-Signaturen weiterhin akzeptiert werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
lua
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
65/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.