LuaLS / LuaLS/lua-language-server
[Feature Request] Required nullable arguments
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Lua
- Sterne
- 4.4k
- Forks
- 442
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
When calling Java methods from Kahlua, the number of arguments is used to determine the appropriate implementation to call. Because of this, arguments that can be nil are required in the function call for appropriate resolution. This is usually not a concern in Lua, but it could be.
In this example, both f() and f(nil) are appropriate, since the value of x defaults to nil.
---@param x integer?
local function f(x) end
In this example, however, the behaviors of t.f() and t.f(nil) are not equivalent.
(Admittedly, this is a contrived example. Nonetheless, it shows that this would not only be useful for strange cases like Kahlua's implementation.)
---@class Example
---@field f fun(x: integer?)
t = {
f = function(...)
assert(select('#', ...) == 1)
end
}
I don't feel strongly about the annotation that would be used to specify this, but ! comes to mind:
---@class Example
---@field f fun(x: integer?!)
t = {
f = function(...)
assert(select('#', ...) == 1)
end
}
The ?!/!? pair may be redundant, since non-nil argument types are always required. It would also be feasible to represent required but nil-able arguments with ! alone.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Es ist keine Repository-Datei oder kein Test benannt. Beginne damit, die Pfade für die Verarbeitung von Annotationen und die Auflösung der Argumentanzahl zu finden, die für Lua-Funktionen und Java/Kahlua-Aufrufe relevant sind. Vergleiche die vorgeschlagenen Formen ?!, !? und !, definiere anschließend die Abdeckung für weggelassene gegenüber expliziten nil-Argumenten und bestätige die beabsichtigte Syntax vor der Implementierung.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100