LuaLS / LuaLS/lua-language-server
string.unpack vararg returns
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?
Linux
### What is the issue affecting?
Annotations, Type Checking, Completion
### Expected Behaviour
The current `string.unpack` annotations (for the returns) are as following:
```lua
---@param fmt string
---@param s string
---@param pos? integer
---@return any ...
---@return integer offset
---@nodiscard
function string.unpack(fmt, s, pos) end
```
The function will indeed return any number of `any` returns followed by a single integer return for the new offset. As such you would expect that in the following example code, all of the returns are `any` except the last return be `integer`:
```lua
local a, b, c, d, offset = string.unpack('I2I2I2I2', "some binary data")
```
### Actual Behaviour
Instead of the `a, b, c, d` being typed as `any` and `offset` being typed as `integer`, we instead see that `a` is typed as `any`, `b` is typed as `integer`, and `c, d, offset` are typed as `nil`.
This happen because it is not supported for a function to return a vararg followed by any return; it is always that vararg returns are the last return. Because of that, only the first return is typed as `any` and from there the second `@return` takes.
### Reproduction steps
1. Copy the example code.
2. Hover over each return variable to notice the type.
### 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 l’annotation de string.unpack et reproduisez le problème dans l’extension Visual Studio Code en survolant chaque variable retournée. Suivez la manière dont le vérificateur de types traite un vararg suivi du retour de l’offset. Le travail est terminé lorsque les valeurs de unpack sont typées en any et que l’offset final est typé en integer.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- lua
- Domaine
- tooling
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100