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.

オープン
#3,120 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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

![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_

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された test.lua の例を使用し、Visual Studio Code extension を通じて Lua language server の問題を再現します。まず、コロンで定義されたメソッドと注釈付きの self パラメーターの型チェックを追跡します。self が Zone として扱われ、例でエラーが発生しなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。