LuaLS / LuaLS/lua-language-server

string.unpack vararg returns

Abierto
#2,261 2 comentarios 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement
Lenguaje dominante
Lua
Estrellas
4.4k
Forks
442
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### 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_

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la anotación de string.unpack y reproduce el problema en la extensión de Visual Studio Code pasando el cursor sobre cada variable devuelta. Sigue cómo el comprobador de tipos maneja un vararg seguido del retorno del offset. Se considera terminado cuando los valores de unpack están tipados como any y el offset final está tipado como integer.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
lua
Área
tooling
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.