LuaLS / LuaLS/lua-language-server
Error returning derived classes
オープン
まだ誰も着手していません。
- 主要言語
- 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?
Annotations
Expected Behaviour
---@class Thing
---@field getCreature fun(self:Thing):Creature?
---@field getPlayer fun(self:Thing):Player?
---@field getMonster fun(self:Thing):Monster?
---@field getNpc fun(self:Thing):Npc?
---@class Creature:Thing
---@field getCreature fun(self:Creature):Creature
---@field getPlayer fun(self:Creature):Player?
---@field getMonster fun(self:Creature):Monster?
---@class Player:Creature
---@field getPlayer fun(self:Player):Player
---@field getMonster fun(self:Player):nil
---@field getNpc fun(self:Player):nil
---@class Monster:Creature
---@field getPlayer fun(self:Monster):nil
---@field getMonster fun(self:Monster):Monster
---@field getNpc fun(self:Monster):nil
function Creature:getCreature() return self end
function Creature:getPlayer() return self:isPlayer() and self or nil end
function Creature:getMonster() return self:isMonster() and self or nil end
function Creature:getNpc() return self:isNpc() and self or nil end
Actual Behaviour
The current behavior is that the methods: getMonster, getNpc throw the following error:
Annotations specify that return value #1 has a type of `Monster?`, returning value of type `Creature|nil` here instead.
- `Creature` cannot match `Monster?`
- Type `Creature` cannot match `nil`
- Type `Thing` cannot match `nil`
- Type `Creature` cannot match `Monster`
- Type `Thing` cannot match `Monster`Lua Diagnostics.(return-type-mismatch)
The error does not occur with the Player class which is also derived from the Creature class
Reproduction steps
- Use the code of the expected behavior
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue の Lua スニペットを使って Visual Studio Code で診断を再現し、getMonster と getNpc の派生クラスの戻り値アノテーションに焦点を当てます。不一致の原因となっているアノテーションと型チェックの動作を追跡します。完了の条件は、Player について報告された動作を維持しながら、再現時に誤った戻り値型エラーが報告されなくなることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100