Skip to content

Commit 2896a05

Browse files
committed
fix close-non-object
1 parent 3020a6e commit 2896a05

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

script/core/diagnostics/close-non-object.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local files = require 'files'
22
local guide = require 'parser.guide'
33
local lang = require 'language'
4+
local vm = require 'vm'
45

56
return function (uri, callback)
67
local state = files.getState(uri)
@@ -23,18 +24,15 @@ return function (uri, callback)
2324
}
2425
return
2526
end
26-
if source.value.type == 'nil'
27-
or source.value.type == 'number'
28-
or source.value.type == 'integer'
29-
or source.value.type == 'boolean'
30-
or source.value.type == 'table'
31-
or source.value.type == 'function' then
27+
local infer = vm.getInfer(source.value)
28+
if not infer:hasClass()
29+
and not infer:hasType 'nil'
30+
and infer:view('any', uri) ~= 'any' then
3231
callback {
3332
start = source.value.start,
3433
finish = source.value.finish,
3534
message = lang.script.DIAG_COSE_NON_OBJECT,
3635
}
37-
return
3836
end
3937
end)
4038
end

test/diagnostics/common.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,13 @@ TEST [[
333333
local _ <close> = <!1!>
334334
]]
335335

336-
--TEST [[
337-
--local _ <close> = <!''!>
338-
--]]
339-
--
340-
--TEST [[
341-
--local c <close> = <!(function () return 1 end)()!>
342-
--]]
336+
TEST [[
337+
local _ <close> = <!''!>
338+
]]
339+
340+
TEST [[
341+
local c <close> = <!(function () return 1 end)()!>
342+
]]
343343

344344
config.get(nil, 'Lua.diagnostics.disable')['unused-local'] = true
345345
TEST [[

0 commit comments

Comments
 (0)