LuaLS / LuaLS/lua-language-server
Even if the `self` parameter is defined with another type, it is automatically defined in the body of the function as the type of the object.
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?
Windows
### What is the issue affecting?
Type Checking
### Expected Behaviour
`test.lua` - No error.
```lua
---@class Position
---@field x number
---@field y number
---@field z number
Position = {}
---@class Creature
---@field teleportTo fun(self:Creature, position:Position):nil
Creature = {}
---@class Zone
---@field getName fun(self:Zone):string
---@overload fun(): Zone
Zone = {}
---@class Event
---@field onCreatureEnter fun(self:Zone, creature:Creature):nil
---@field onCreatureLeave fun(self:Zone, creature:Creature):nil
---@field register fun(self:Event):nil
---@overload fun(): Event
Event = {}
local zone = Zone()
local zoneEvent = Event()
function zoneEvent:onCreatureEnter(creature)
if self:getName() == zone:getName() then
creature:teleportTo(Position(0, 0, 0))
end
end
zoneEvent:register()
```
### Actual Behaviour
`test.lua` - Found error.
```lua
---@class Position
---@field x number
---@field y number
---@field z number
Position = {}
---@class Creature
---@field teleportTo fun(self:Creature, position:Position):nil
Creature = {}
---@class Zone
---@field getName fun(self:Zone):string
---@overload fun(): Zone
Zone = {}
---@class Event
---@field onCreatureEnter fun(self:Zone, creature:Creature):nil
---@field onCreatureLeave fun(self:Zone, creature:Creature):nil
---@field register fun(self:Event):nil
---@overload fun(): Event
Event = {}
local zone = Zone()
local zoneEvent = Event()
function zoneEvent:onCreatureEnter(creature)
if self:getName() == zone:getName() then
creature:teleportTo(Position(0, 0, 0))
end
end
zoneEvent:register()
```
Images example


### Reproduction steps
Just copy the code and test it in any Lua file.
`self` should be of type `Zone`, as that's how it's defined in the meta file.
### 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
Reproduce el problema en el Lua language server mediante la Visual Studio Code extension usando el ejemplo test.lua proporcionado. Empieza rastreando la comprobación de tipos de los métodos definidos con dos puntos y del parámetro self anotado; la tarea está terminada cuando self se trata como Zone y el ejemplo no produce ningún error.
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