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.
まだ誰も着手していません。
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
### 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_
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された test.lua の例を使用し、Visual Studio Code extension を通じて Lua language server の問題を再現します。まず、コロンで定義されたメソッドと注釈付きの self パラメーターの型チェックを追跡します。self が Zone として扱われ、例でエラーが発生しなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100