summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/diagnostics/cast-local-type.lua25
-rw-r--r--script/core/hover/label.lua4
-rw-r--r--script/glob/gitignore.lua3
-rw-r--r--test/diagnostics/common.lua19
4 files changed, 37 insertions, 14 deletions
diff --git a/script/core/diagnostics/cast-local-type.lua b/script/core/diagnostics/cast-local-type.lua
index f466f923..4b7f7e84 100644
--- a/script/core/diagnostics/cast-local-type.lua
+++ b/script/core/diagnostics/cast-local-type.lua
@@ -24,21 +24,28 @@ return function (uri, callback)
if vm.getInfer(loc):hasUnknown(uri) then
return
end
+ local canSetNil = vm.getInfer(loc):hasClass(uri)
+ or vm.getInfer(loc):hasType(uri, 'table')
for _, ref in ipairs(loc.ref) do
if ref.type == 'setlocal' then
await.delay()
local refNode = vm.compileNode(ref)
- if not vm.isSubType(uri, refNode, locNode) then
- callback {
- start = ref.start,
- finish = ref.finish,
- message = lang.script('DIAG_CAST_LOCAL_TYPE', {
- loc = vm.getInfer(locNode):view(uri),
- ref = vm.getInfer(refNode):view(uri),
- }),
- }
+ if canSetNil and vm.getInfer(ref):view(uri) == 'nil' then
+ goto CONTINUE
end
+ if vm.isSubType(uri, refNode, locNode) then
+ goto CONTINUE
+ end
+ callback {
+ start = ref.start,
+ finish = ref.finish,
+ message = lang.script('DIAG_CAST_LOCAL_TYPE', {
+ loc = vm.getInfer(locNode):view(uri),
+ ref = vm.getInfer(refNode):view(uri),
+ }),
+ }
end
+ ::CONTINUE::
end
end)
end
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index e725f6b0..a91ca074 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -56,9 +56,9 @@ local function asValue(source, title)
or type == 'any'
or type == 'unknown'
or type == 'nil') then
- type = nil
+ else
+ pack[#pack+1] = type
end
- pack[#pack+1] = type
if literal then
pack[#pack+1] = '='
pack[#pack+1] = literal
diff --git a/script/glob/gitignore.lua b/script/glob/gitignore.lua
index a6a3df3e..de8fd005 100644
--- a/script/glob/gitignore.lua
+++ b/script/glob/gitignore.lua
@@ -168,9 +168,6 @@ end
---@async
function mt:scan(path, callback, hook)
local files = {}
- if type(callback) ~= 'function' then
- callback = nil
- end
local list = {}
---@async
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index b5f490a2..f80aee0a 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -1644,3 +1644,22 @@ local x
x = 1
]]
+
+TEST [[
+---@diagnostic disable: unused-local
+
+local x = {}
+
+x = nil
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+
+---@class A
+
+---@type A
+local x
+
+x = nil
+]]