summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/vm/visible.lua21
-rw-r--r--test/diagnostics/common.lua14
2 files changed, 34 insertions, 1 deletions
diff --git a/script/vm/visible.lua b/script/vm/visible.lua
index 50c37bf0..72a1370c 100644
--- a/script/vm/visible.lua
+++ b/script/vm/visible.lua
@@ -105,6 +105,20 @@ function vm.getDefinedClass(suri, source)
return nil
end
+---@param source parser.object
+---@return vm.global?
+local function getEnvClass(source)
+ local func = guide.getParentFunction(source)
+ if not func or func.type ~= 'function' then
+ return nil
+ end
+ local self = func.args and func.args[1]
+ if not self or self.type ~= 'self' then
+ return nil
+ end
+ return vm.getDefinedClass(guide.getUri(source), self)
+end
+
---@param parent parser.object
---@param field parser.object
function vm.isVisible(parent, field)
@@ -117,9 +131,14 @@ function vm.isVisible(parent, field)
return true
end
local suri = guide.getUri(parent)
+ -- check <?obj?>.x
local myClass = vm.getDefinedClass(suri, parent)
if not myClass then
- return false
+ -- check function <?mt?>:X() ... end
+ myClass = getEnvClass(parent)
+ if not myClass then
+ return false
+ end
end
if myClass == class then
return true
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index 4194fcdc..3d414906 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -2196,3 +2196,17 @@ function mt:init()
print(self.x)
end
]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field private x number
+local mt = {}
+
+function mt:init()
+ ---@type A
+ local obj = {}
+
+ obj.x = 1
+end
+]]