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.

Aberta
#3,120 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
Lua
Estrelas
4.4k
Forks
442
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Reproduza o problema no Lua language server por meio da Visual Studio Code extension usando o exemplo test.lua fornecido. Comece rastreando a verificação de tipos para métodos definidos com dois-pontos e para o parâmetro self anotado; a tarefa estará concluída quando self for tratado como Zone e o exemplo não produzir nenhum erro.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
lua
Domínio
devtools
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.