LuaLS / LuaLS/lua-language-server

string.unpack vararg returns

Aperta
#2,261 2 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement
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?

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_

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con l’annotazione di string.unpack e riproduci il problema nell’estensione Visual Studio Code passando il mouse su ogni variabile restituita. Traccia il modo in cui il verificatore dei tipi gestisce un vararg seguito dal valore di ritorno dell’offset. Il lavoro è completato quando i valori di unpack sono tipizzati come any e l’offset finale è tipizzato come integer.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
lua
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.