summaryrefslogtreecommitdiff
path: root/test/type_inference/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/type_inference/init.lua')
-rw-r--r--test/type_inference/init.lua116
1 files changed, 116 insertions, 0 deletions
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 566e847a..efcc5fea 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -1813,6 +1813,17 @@ TEST 'integer' [[
---@type integer?
local x
+if not x then
+ return
+end
+
+print(<?x?>)
+]]
+
+TEST 'integer' [[
+---@type integer?
+local x
+
if xxx and x then
print(<?x?>)
end
@@ -2153,6 +2164,15 @@ print(<?x?>)
]]
TEST 'integer' [[
+---@type integer?
+local x
+
+while x do
+ print(<?x?>)
+end
+]]
+
+TEST 'integer' [[
---@type fun():integer?
local iter
@@ -2237,6 +2257,19 @@ local x
print(<?x?>)
]]
+TEST 'unknown?' [[
+---@type string?
+local x
+
+if x then
+ return
+else
+ print(<?x?>)
+end
+
+print(x)
+]]
+
TEST 'string' [[
---@type string?
local x
@@ -2298,6 +2331,18 @@ end
print(<?t?>)
]]
+TEST 'unknown?' [[
+---@type integer?
+local t
+
+if t then
+else
+ print(<?t?>)
+end
+
+print(t)
+]]
+
TEST 'table|unknown' [[
local function f()
if x then
@@ -2375,3 +2420,74 @@ TEST '`1`|`true`' [[
---@type `1` | `true`
local <?x?>
]]
+
+TEST 'function' [[
+local x
+
+function x() end
+
+print(<?x?>)
+]]
+
+TEST 'unknown' [[
+local x
+
+if x.field == 'haha' then
+ print(<?x?>)
+end
+]]
+
+TEST 'string' [[
+---@type string?
+local t
+
+if not t or xxx then
+ return
+end
+
+print(<?t?>)
+]]
+
+TEST 'table' [[
+---@type table|nil
+local t
+
+return function ()
+ if not t then
+ return
+ end
+
+ print(<?t?>)
+end
+]]
+
+TEST 'table' [[
+---@type table|nil
+local t
+
+f(function ()
+ if not t then
+ return
+ end
+
+ print(<?t?>)
+end)
+]]
+
+TEST 'table' [[
+---@type table?
+local t
+
+t = t or {}
+
+print(<?t?>)
+]]
+
+TEST 'unknown|nil' [[
+local x
+
+if x == nil then
+end
+
+print(<?x?>)
+]]