Skip to content

Commit d2df778

Browse files
committed
feat: skip warning when instance variable overriding class function
1 parent a4b71fb commit d2df778

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

script/core/diagnostics/duplicate-set-field.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ return function (uri, callback)
6868
if not defValue or defValue.type ~= 'function' then
6969
goto CONTINUE
7070
end
71+
if vm.getDefinedClass(guide.getUri(def), def.node)
72+
and not vm.getDefinedClass(guide.getUri(src), src.node)
73+
then
74+
-- allow type variable to override function defined in class variable
75+
goto CONTINUE
76+
end
7177
callback {
7278
start = src.start,
7379
finish = src.finish,

test/diagnostics/duplicate-set-field.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,29 @@ else
7272
function X.f() end
7373
end
7474
]]
75+
76+
TEST [[
77+
---@class A
78+
X = {}
79+
80+
function X:f() end
81+
82+
---@type x
83+
local x
84+
85+
function x:f() end
86+
]]
87+
88+
TEST [[
89+
---@class A
90+
X = {}
91+
92+
function X:f() end
93+
94+
---@type x
95+
local x
96+
97+
function <!x:f!>() end
98+
99+
function <!x:f!>() end
100+
]]

0 commit comments

Comments
 (0)