LuaLS / LuaLS/lua-language-server
[Feature Request] Required nullable arguments
Nessuno ha ancora preso questa issue.
- Lingua principale
- Lua
- Stelle
- 4.4k
- Fork
- 442
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Non è indicato alcun file o test del repository. Inizia individuando i percorsi di gestione delle annotazioni e di risoluzione del numero di argomenti rilevanti per le funzioni Lua e le chiamate Java/Kahlua. Confronta le forme proposte `?!`, `!?` e `!`, quindi definisci la copertura per gli argomenti omessi rispetto agli argomenti `nil` espliciti e conferma la sintassi prevista prima dell'implementazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100