LuaLS / LuaLS/lua-language-server
Over-zealous 'Field `_field` is protected' warning in class-created closure functions
まだ誰も着手していません。
- 主要言語
- 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?
Diagnostics/Syntax Checking
Expected Behaviour
Functions created from within class methods should be allowed to access protected (and private) members of that class.
Essentially, any functions inside a class method should inheret that method's access- this is a simple pattern that maintains encapsulation of exactly those private/protected fields, as the code is still clearly "owned" by the encapsulating class.
Actual Behaviour
In some scenarios, functions within class methods that access protected members of that class are being marked with the 'Field _field is protected' warning. See Repro Steps for code sample.
Reproduction steps
---@class DynamicDude
---@field _field string?
local DynamicDude = {}
function DynamicDude:demo()
self:setup(function(self)
-- This disable shouldn't be necessary
---@diagnostic disable-next-line: invisible
self._field = 'test'
end)
---@param self DynamicDude
local function closure(self)
-- This disable shouldn't be necessary
---@diagnostic disable-next-line: invisible
self._field = 'test'
end
self.dynamic_fn = function(self)
self._field = 'test'
end
end
---@param fn fun(self:DynamicDude)
function DynamicDude:setup(fn)
self.dynamic_fn = fn
end
Additional Notes
FEATURE REQUEST: I'd actually love to have a setting that just said "all variables named self are assumed to indicate valid access to private/protected members", to cover all my bases. Happy to dig up some examples / explain myself more if that's useful.
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された DynamicDude の例を Visual Studio Code 拡張機能で再現し、クラスメソッド内で作成された closures を diagnostics がどのように分類するかを調べます。これらの closures が、目に見えない警告なしにクラスの protected または private members にアクセスでき、関連しないアクセスについては引き続き診断されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100