LuaLS / LuaLS/lua-language-server
Generics don't expand alias types/don't work with other parameters
Personne n'a encore pris cette issue.
- Langage dominant
- Lua
- Étoiles
- 4.4k
- Forks
- 442
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire les exemples dans la Visual Studio Code Extension avec LuaLS, en vous concentrant sur la vérification des types pour les paramètres génériques et les aliased function types. Comparez les cas utilisant TestFunction avec ceux utilisant le type de base string. C'est terminé lorsque les alias sont développés de manière cohérente, que les paramètres des callbacks reçoivent les types attendus et que les appels invalides ou les retours manquants produisent des avertissements.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- lua
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 38/100