LuaLS / LuaLS/lua-language-server
Generics don't expand alias types/don't work with other parameters
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
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?
Type Checking
Expected Behaviour
With a code sample like this:
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@param func T
local function testSecond(name, func) end
testSecond("TestFunction", function(abc) end)
I would expect abc to have a type of string, and the function to be type checked and require a return.
Actual Behaviour
Instead, abc has the any type and the function requires no return.
I further tested with a different code sample:
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@return T
local function testSecond(name, func) return function(abc) end end
local cool = testSecond("TestFunction", function(abc) end)
cool()
This shows no warnings and does not require me to pass any arguments to cool(), which is incorrect. Hovering over cool provides a type of 'TestFunction' and does not show the full expanded type of the alias, unlike other variables with a type of an alias. That rings the same with this code sample I also tested:
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@param func fun(cool: T)
local function testSecond(name, func) end
testSecond("TestFunction", function(abc) end)
where hovering over abc provides me with a 'TestFunction' unexpanded type.
However, correct behavior is seen with the following code sample using the base string type;
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@param func fun(cool: T)
---@return T
local function testSecond(name, func) end
local cool = testSecond("string", function(abc) abc.cool = "hi" end)
local testfind = cool:find("test")
Autocomplete is provided for :find() and abc.cool = "hi" throws the correct warning for field injection.
And most confusing of all, this code sample behaves in line with expected behavior, and the alias is fully expanded.
---@alias TestFunction fun(abc: string): integer
---@generic T
---@param name `T`
---@param func fun(cool: T)
---@return T
local function testSecond(name, func) end
local cool = testSecond("TestFunction",
---@param abc TestFunction
function(abc)
abc()
end
)
This also doesn't work, which I kind of expected. (no warnings)
Reproduction steps
- Paste code into project with Lua LSP on, see issue
Additional Notes
No response
Log File
No response
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
Inizia riproducendo gli esempi nella Visual Studio Code Extension con LuaLS, concentrandoti sul controllo dei tipi per i parametri generici e gli aliased function types. Confronta i casi che usano TestFunction con quelli che usano il tipo base string. Il lavoro è completato quando gli alias vengono espansi in modo coerente, i parametri dei callback ricevono i tipi previsti e le chiamate non valide o i ritorni mancanti producono avvisi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100