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.

Abierto
#3,120 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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

![Image](https://github.com/user-attachments/assets/db9a8376-9f78-4f5b-bf8e-07ae43cf9e5e)

![Image](https://github.com/user-attachments/assets/fc544284-d735-42ca-baa9-48b3006c4444)

### 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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.