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.
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?
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_
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
Riproduci il problema nel Lua language server tramite la Visual Studio Code extension usando l’esempio test.lua fornito. Inizia tracciando il controllo dei tipi per i metodi definiti con i due punti e per il parametro self annotato; l’attività è completata quando self viene trattato come Zone e l’esempio non produce errori.
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