LuaLS / LuaLS/lua-language-server

Support for a bottom type for non-returning functions

Aperta
#2,443 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

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

Have a way to tag the return type of a function as Bottom, i.e., never returns.

### Actual Behaviour

I have a snippet like this:

```

local function abort(err)
io.stderr:write(err .. "\n")
os.exit(1)
end

local function stuff()
local chunk = loadfile("x.lua")
if not chunk then
abort("failed to loadfile()")
end
chunk()
return {}
end

stuff()
```

which triggers the "need-nil-check" diagnostic on "chunk()" because it doesn't understand that abort() never returns, so i would like to tag abort() (or better tag os.exit() and do return os.exit) as never returning function.

obvious work-around is to do "return abort(...)" instead, but that messes up the return type of stuff() from table to table|nil. so i have to write `abort() return {}` to make the type checker happy which is a bit cumbersome

### Reproduction steps

1. Go to '...'
2. Click '...'
3. See error '...'

### 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 dal percorso di controllo dei tipi per la diagnostica `need-nil-check` e dalle annotazioni esistenti dei tipi restituiti dalle funzioni. Confronta la gestione richiesta di `abort` e `os.exit` con il modo in cui il checker inferisce `stuff()` dopo la chiamata. Il lavoro è completato quando è possibile rappresentare una funzione che non restituisce, evitando così la diagnostica nil senza aggiungere nil al tipo restituito da `stuff()`.

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

Valutazione

Stack tecnologico
lua
Ambito
devtools
Tipo di issue
Funzionalità
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.