summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-21 20:23:41 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-21 20:23:41 +0800
commitbb1244fa62c0158490d2e54da0a19f28f16fe994 (patch)
treebea39497ee52f7b4de442438bad50c90668a0647 /test
parentf76cd50992dab57a57c61e8e6f5f788745544da9 (diff)
downloadlua-language-server-bb1244fa62c0158490d2e54da0a19f28f16fe994.zip
resolve #871 infer called function by params num
Diffstat (limited to 'test')
-rw-r--r--test/type_inference/init.lua125
1 files changed, 125 insertions, 0 deletions
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 5fa70f5f..394ce263 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -2835,3 +2835,128 @@ local b
local <?x?> = echo(b)
]]
+
+TEST 'boolean' [[
+---@return boolean
+function f()
+end
+
+---@param x integer
+---@return number
+function f(x)
+end
+
+local <?x?> = f()
+]]
+
+TEST 'number' [[
+---@return boolean
+function f()
+end
+
+---@param x integer
+---@return number
+function f(x)
+end
+
+local <?x?> = f(1)
+]]
+
+TEST 'boolean' [[
+---@return boolean
+function f()
+end
+
+---@param x integer
+---@return number
+function f(x)
+end
+
+function r0()
+ return
+end
+
+local <?x?> = f(r0())
+]]
+
+TEST 'number' [[
+---@return boolean
+function f()
+end
+
+---@param x integer
+---@return number
+function f(x)
+end
+
+function r1()
+ return 1
+end
+
+local <?x?> = f(r1())
+]]
+
+TEST 'boolean' [[
+---@return boolean
+function f()
+end
+
+---@param x integer
+---@return number
+function f(x)
+end
+
+---@type fun()
+local r0
+
+local <?x?> = f(r0())
+]]
+
+TEST 'number' [[
+---@return boolean
+function f()
+end
+
+---@param x integer
+---@return number
+function f(x)
+end
+
+---@type fun():integer
+local r1
+
+local <?x?> = f(r1())
+]]
+
+TEST 'boolean' [[
+---@overload fun(number, number):string
+---@overload fun(number):number
+---@return boolean
+local function f() end
+
+local <?n1?> = f()
+local n2 = f(0)
+local n3 = f(0, 0)
+]]
+
+TEST 'number' [[
+---@overload fun(number, number):string
+---@overload fun(number):number
+---@return boolean
+local function f() end
+
+local n1 = f()
+local <?n2?> = f(0)
+local n3 = f(0, 0)
+]]
+
+TEST 'string' [[
+---@overload fun(number, number):string
+---@overload fun(number):number
+---@return boolean
+local function f() end
+
+local n1 = f()
+local n2 = f(0)
+local <?n3?> = f(0, 0)
+]]