Skip to content

Commit 2adc249

Browse files
committed
fix #1354
1 parent 59285a7 commit 2adc249

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# changelog
22

3+
## 3.5.1
4+
* `FIX` [#1354](https://github.com./sumneko/lua-language-server/issues/1354)
5+
36
## 3.5.0
47
`2022-7-19`
58
* `NEW` `LuaDoc`: `---@operator`:

script/vm/compiler.lua

+15-6
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
293293
if set.type == 'doc.class' then
294294
-- check ---@field
295295
local hasFounded = {}
296+
297+
local function copyToSearched()
298+
for fieldKey in pairs(hasFounded) do
299+
searchedFields[fieldKey] = true
300+
hasFounded[fieldKey] = nil
301+
end
302+
end
303+
296304
for _, field in ipairs(set.fields) do
297305
local fieldKey = guide.getKeyName(field)
298306
if fieldKey then
@@ -342,8 +350,9 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
342350
end
343351
end
344352
end
353+
copyToSearched()
345354
-- check local field and global field
346-
if not hasFounded[key] and set.bindSource then
355+
if not searchedFields[key] and set.bindSource then
347356
local src = set.bindSource
348357
if src.value and src.value.type == 'table' then
349358
searchFieldSwitch('table', suri, src.value, key, ref, function (field)
@@ -357,22 +366,21 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
357366
end
358367
end)
359368
end
369+
copyToSearched()
360370
searchFieldSwitch(src.type, suri, src, key, ref, function (field)
361371
local fieldKey = guide.getKeyName(field)
362-
if fieldKey and not hasFounded[fieldKey] then
372+
if fieldKey and not searchedFields[fieldKey] then
363373
if not searchedFields[fieldKey]
364374
and guide.isSet(field) then
365375
hasFounded[fieldKey] = true
366376
pushResult(field, true)
367377
end
368378
end
369379
end)
380+
copyToSearched()
370381
end
371382
-- look into extends(if field not found)
372-
if not hasFounded[key] and set.extends then
373-
for fieldKey in pairs(hasFounded) do
374-
searchedFields[fieldKey] = true
375-
end
383+
if not searchedFields[key] and set.extends then
376384
for _, extend in ipairs(set.extends) do
377385
if extend.type == 'doc.extends.name' then
378386
local extendType = vm.getGlobal('type', extend[1])
@@ -381,6 +389,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
381389
end
382390
end
383391
end
392+
copyToSearched()
384393
end
385394
end
386395
end

test/diagnostics/common.lua

+12
Original file line numberDiff line numberDiff line change
@@ -2007,3 +2007,15 @@ local t
20072007
20082008
local _ <close> = t
20092009
]]
2010+
2011+
TEST [[
2012+
---@diagnostic disable: duplicate-set-field
2013+
---@class A
2014+
local m = {}
2015+
2016+
function m.ff() end
2017+
2018+
function m.ff(x) end
2019+
2020+
m.ff(1)
2021+
]]

0 commit comments

Comments
 (0)