summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
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)