summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-18 01:03:25 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-18 01:03:25 +0800
commit6df9d8376bc5339a8c4218cc261dc76d7ac8e7ad (patch)
treea6e13efaf733f6b3ef618ece150aa1fb3579f456 /script
parent7b35e39b5eae7c3445cd9ec4d16637185bc26b93 (diff)
downloadlua-language-server-6df9d8376bc5339a8c4218cc261dc76d7ac8e7ad.zip
update
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/assign-type-mismatch.lua7
-rw-r--r--script/vm/compiler.lua12
2 files changed, 19 insertions, 0 deletions
diff --git a/script/core/diagnostics/assign-type-mismatch.lua b/script/core/diagnostics/assign-type-mismatch.lua
index 9a101be1..d301faed 100644
--- a/script/core/diagnostics/assign-type-mismatch.lua
+++ b/script/core/diagnostics/assign-type-mismatch.lua
@@ -5,6 +5,7 @@ local vm = require 'vm'
local await = require 'await'
local checkTypes = {
+ 'setlocal',
'setglobal',
'setfield',
'setindex',
@@ -27,6 +28,12 @@ return function (uri, callback)
return
end
await.delay()
+ if source.type == 'setlocal' then
+ local locNode = vm.compileNode(source.node)
+ if not locNode:getData 'hasDefined' then
+ return
+ end
+ end
local varNode = vm.compileNode(source)
local valueNode = vm.compileNode(value)
if vm.getInfer(varNode):hasUnknown(uri) then
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index bc85407d..36b826ae 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1086,6 +1086,18 @@ local binarySwich = util.switch()
[1] =result,
})
else
+ if op == '+'
+ or op == '-'
+ or op == '*'
+ or op == '//'
+ or op == '%' then
+ local uri = guide.getUri(source)
+ if vm.getInfer(source[1]):view(uri) == 'integer'
+ and vm.getInfer(source[2]):view(uri) == 'integer' then
+ vm.setNode(source, vm.declareGlobal('type', 'integer'))
+ return
+ end
+ end
vm.setNode(source, vm.declareGlobal('type', 'number'))
end
end)