LuaLS / LuaLS/lua-language-server
Widening cast has no effect
Nadie ha tomado este issue todavía.
- 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, 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_
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza ejecutando las tres reproducciones en Lua del issue y compara la información del hover con los diagnósticos de asignación. Traza el procesamiento de los casts y la ruta posterior de comprobación de tipos para las variables locales. Después, añade o actualiza la cobertura para que los casts de ampliación afecten a las comprobaciones de asignación sin introducir errores contradictorios.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- lua
- Área
- devtools
- 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