summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/completion/completion.lua2
-rw-r--r--script/core/diagnostics/assign-type-mismatch.lua2
-rw-r--r--script/parser/guide.lua1
-rw-r--r--script/vm/compiler.lua12
-rw-r--r--test/diagnostics/type-check.lua10
5 files changed, 24 insertions, 3 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 1ddd9890..165dbac5 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1241,7 +1241,7 @@ local function tryIndex(state, position, results)
if not parent then
return
end
- local word = parent.next.index[1]
+ local word = parent.next and parent.next.index and parent.next.index[1]
checkField(state, word, position, position, parent, oop, results)
end
diff --git a/script/core/diagnostics/assign-type-mismatch.lua b/script/core/diagnostics/assign-type-mismatch.lua
index c6a4195c..ae4b3512 100644
--- a/script/core/diagnostics/assign-type-mismatch.lua
+++ b/script/core/diagnostics/assign-type-mismatch.lua
@@ -50,7 +50,7 @@ return function (uri, callback)
end
end
end
- local varNode = vm.compileNode(source)
+ local varNode = vm.compileNode(source)
if vm.canCastType(uri, varNode, valueNode) then
return
end
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 62914974..3f68ccd2 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -1247,6 +1247,7 @@ local basicTypeMap = {
['false'] = true,
['nil'] = true,
['boolean'] = true,
+ ['integer'] = true,
['number'] = true,
['string'] = true,
['table'] = true,
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index fade0a78..99bd0691 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1211,7 +1211,17 @@ local compilerSwitch = util.switch()
or source.parent.type == 'tableindex'
or source.parent.type == 'setfield'
or source.parent.type == 'setindex' then
- vm.setNode(source, vm.compileNode(source.parent))
+ local parentNode = vm.compileNode(source.parent)
+ for _, pn in ipairs(parentNode) do
+ if pn.type == 'global'
+ and pn.cate == 'type' then
+ if not guide.isBasicType(pn.name) then
+ vm.setNode(source, pn)
+ end
+ elseif pn.type == 'doc.type.table' then
+ vm.setNode(source, pn)
+ end
+ end
end
end)
: case 'function'
diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua
index cbf9265c..20c611ab 100644
--- a/test/diagnostics/type-check.lua
+++ b/test/diagnostics/type-check.lua
@@ -300,5 +300,15 @@ local y
t = y
]]
+TEST [[
+---@class A
+local m
+
+---@type number
+m.x = 1
+
+<!m.x!> = {}
+]]
+
config.remove(nil, 'Lua.diagnostics.disable', 'unused-local')
config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')