summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/vm.lua17
-rw-r--r--server/test/type_inference/init.lua8
2 files changed, 24 insertions, 1 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index af3e00ed..13232b8b 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -240,6 +240,7 @@ end
function mt:buildFunction(exp, object)
local func = self:createValue('function')
func.args = {}
+ func.argValues = {}
if not exp then
return func
@@ -264,6 +265,7 @@ function mt:buildFunction(exp, object)
if arg.type == 'name' then
local var = self:createLocal(arg[1], arg)
func.args[#func.args+1] = var
+ func.argValues[#func.args] = self:getValue(var)
elseif arg.type == '...' then
local dots = self:createDots(arg)
func.args[#func.args+1] = dots
@@ -712,7 +714,11 @@ function mt:getBinary(exp)
or op == '>='
or op == '<'
or op == '>'
- or op == '~='
+ then
+ self:inference(v1, 'number')
+ self:inference(v2, 'number')
+ return self:createValue('boolean')
+ elseif op == '~='
or op == '=='
then
return self:createValue('boolean')
@@ -723,8 +729,12 @@ function mt:getBinary(exp)
or op == '>>'
or op == '//'
then
+ self:inference(v1, 'integer')
+ self:inference(v2, 'integer')
return self:createValue('integer')
elseif op == '..' then
+ self:inference(v1, 'string')
+ self:inference(v2, 'string')
return self:createValue('string')
elseif op == '+'
or op == '-'
@@ -733,6 +743,8 @@ function mt:getBinary(exp)
or op == '^'
or op == '%'
then
+ self:inference(v1, 'number')
+ self:inference(v2, 'number')
return self:createValue('number')
end
return nil
@@ -745,10 +757,13 @@ function mt:getUnary(exp)
if op == 'not' then
return self:createValue('boolean')
elseif op == '#' then
+ self:inference(v1, 'table')
return self:createValue('integer')
elseif op == '-' then
+ self:inference(v1, 'number')
return self:createValue('number')
elseif op == '~' then
+ self:inference(v1, 'integer')
return self:createValue('integer')
end
return nil
diff --git a/server/test/type_inference/init.lua b/server/test/type_inference/init.lua
index 733fd99a..33e368ea 100644
--- a/server/test/type_inference/init.lua
+++ b/server/test/type_inference/init.lua
@@ -150,3 +150,11 @@ x(1)
TEST 'table' [[
setmetatable(<?b?>)
]]
+
+TEST 'number' [[
+local function x(a)
+ _ = a + 1
+end
+local b
+x(<?b?>)
+]]