LuaLS / LuaLS/lua-language-server
Widening cast has no effect
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?
Linux
### What is the issue affecting?
Annotations, Type Checking, Hover
### Expected Behaviour
Cast unconditionally overwrites the variable's type with the new type.
### Actual Behaviour
Cast is ignored and in some cases causes additional type check errors.
### Reproduction steps
```lua
---@param str string
local function foo(str)
---@cast str +?
if str == '' then str = nil end
end
```
Note how it produces an error on assignment:
```
This variable is defined as type `string`. Cannot convert its type to `nil`.
- `nil` cannot match `string`
- Type `nil` cannot match `string` Lua Diagnostics.(cast-local-type)
```
Note also that the tooltip for `str` in the comparison says correctly that it is a `string?`. But this has no observable effect on the actual type.
Example two (attempted workaround):
```lua
---@param str string
local function foo(str)
---@cast str string?
if str == '' then str = nil end
end
```
Note how the cast causes a type check error now, which makes no sense.
Example three (from the wiki on cast, modified to actually verify that the cast worked):
```lua
---@type integer
local x
---@cast x +boolean
x = false
```
Note how it produces an error, similarly to the first example. You would expect at least the example from the official documentation itself to work, but it doesn't. This leads me to conclude this is a bug.
### Additional Notes
_No response_
### Log File
_No response_
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo le tre riproduzioni in Lua presenti nell'issue e confronta le informazioni dell'hover con la diagnostica delle assegnazioni. Traccia la gestione dei cast e il successivo percorso di verifica dei tipi per le variabili locali, quindi aggiungi o aggiorna la coverage in modo che i cast di widening influenzino i controlli delle assegnazioni senza introdurre errori contraddittori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100