local files = require 'files' local guide = require 'parser.guide' local config = require 'config' local catch = require 'catch' local vm = require 'vm' rawset(_G, 'TEST', true) local function getSource(pos) local ast = files.getState('') local result guide.eachSourceContain(ast.ast, pos, function (source) if source.type == 'local' or source.type == 'getlocal' or source.type == 'setlocal' or source.type == 'setglobal' or source.type == 'getglobal' or source.type == 'field' or source.type == 'method' or source.type == 'function' or source.type == 'table' then result = source end end) return result end function TEST(wanted) return function (script) local newScript, catched = catch(script, '?') files.setText('', newScript) local source = getSource(catched['?'][1][1]) assert(source) local result = vm.getInfer(source):view() if wanted ~= result then vm.getInfer(source):view() end assert(wanted == result) files.remove('') end end TEST 'string' [[ local = '111' ]] TEST 'boolean' [[ local = true ]] TEST 'integer' [[ local = 1 ]] TEST 'number' [[ local = 1.0 ]] TEST 'unknown' [[ local ]] TEST 'unknown' [[ local var = y ]] TEST 'any' [[ function f() end ]] TEST 'any' [[ function f() x = 1 end ]] TEST 'string' [[ local var = '111' t. = var ]] TEST 'string' [[ local var = '111' ]] TEST 'string' [[ local var = '111' ]] TEST 'string' [[ local var var = '111' print() ]] TEST 'function' [[ function () end ]] TEST 'function' [[ local function () end ]] TEST 'function' [[ local xx = function () end ]] TEST 'table' [[ local = {} ]] TEST 'unknown' [[ () ]] TEST 'boolean' [[ = not y ]] TEST 'integer' [[ = #y ]] TEST 'integer' [[ = #'aaaa' ]] TEST 'integer' [[ = #{} ]] TEST 'number' [[ = - y ]] TEST 'number' [[ = - 1.0 ]] TEST 'integer' [[ = ~ y ]] TEST 'integer' [[ = ~ 1 ]] TEST 'integer' [[ local a = true local b = 1 = a and b ]] TEST 'integer' [[ local a = false local b = 1 = a or b ]] TEST 'boolean' [[ = a == b ]] TEST 'integer' [[ = a << b ]] TEST 'integer' [[ = 1 << 2 ]] TEST 'string' [[ = a .. b ]] TEST 'string' [[ = 'a' .. 'b' ]] TEST 'string' [[ = 'a' .. 1 ]] TEST 'string' [[ = 'a' .. 1.0 ]] TEST 'number' [[ = a + b ]] TEST 'number' [[ = 1 + 2.0 ]] TEST 'integer' [[ = 1 + 2 ]] TEST 'tablelib' [[ ---@class tablelib table = {} () ]] TEST 'string' [[ _VERSION = 'Lua 5.4' = _VERSION ]] TEST 'function' [[ ---@class stringlib local string string.xxx = function () end return ('x'). ]] TEST 'function' [[ ---@class stringlib String = {} String.xxx = function () end return ('x'). ]] TEST 'function' [[ ---@class stringlib local string string.xxx = function () end = ('x').xxx ]] TEST 'function' [[ ---@class stringlib local string string.xxx = function () end _VERSION = 'Lua 5.4' = _VERSION.xxx ]] TEST 'table' [[ = setmetatable({}) ]] TEST 'integer' [[ local function x() return 1 end = x() ]] TEST 'integer|nil' [[ local function x() return 1 return nil end = x() ]] TEST 'unknown|nil' [[ local function x() return a return nil end = x() ]] TEST 'unknown|nil' [[ local function x() return nil return f() end = x() ]] TEST 'unknown' [[ local function x() return nil return f() end _, = x() ]] TEST 'integer' [[ local function x() return 1 end _, = pcall(x) ]] TEST 'integer' [[ function x() return 1 end _, = pcall(x) ]] TEST 'integer' [[ local function x() return 1 end _, = xpcall(x) ]] TEST 'A' [[ ---@class A ---@return A local function f2() end local function f() return f2() end local = f() ]] -- 不根据调用者的输入参数来推测 --TEST 'number' [[ --local function x(a) -- return --end --x(1) --]] --TEST 'table' [[ --setmetatable() --]] -- 不根据对方函数内的使用情况来推测 TEST 'unknown' [[ local function x(a) _ = a + 1 end local b x() ]] TEST 'unknown' [[ local function x(a, ...) local _, , _ = ... end x(nil, 'xx', 1, true) ]] -- 引用不跨越参数 TEST 'unknown' [[ local function x(a, ...) return true, 'ss', ... end local _, _, _, , _ = x(nil, true, 1, 'yy') ]] TEST 'unknown' [[ local = next() ]] TEST 'unknown' [[ local a, b function a() return b() end function b() return a() end local = a() ]] TEST 'class' [[ ---@class class local ]] TEST 'string' [[ ---@class string ---@type string local ]] TEST '1' [[ ---@type 1 local ]] TEST 'string[]' [[ ---@class string ---@type string[] local ]] TEST 'string|table' [[ ---@class string ---@class table ---@type string | table local ]] TEST [['enum1'|'enum2']] [[ ---@type 'enum1' | 'enum2' local ]] TEST [["enum1"|"enum2"]] [[ ---@type "enum1" | "enum2" local ]] config.set(nil, 'Lua.hover.expandAlias', false) TEST 'A' [[ ---@alias A 'enum1' | 'enum2' ---@type A local ]] TEST 'A' [[ ---@alias A 'enum1' | 'enum2' | A ---@type A local ]] TEST 'A' [[ ---@alias A 'enum1' | 'enum2' | B ---@type A local ]] config.set(nil, 'Lua.hover.expandAlias', true) TEST [['enum1'|'enum2']] [[ ---@alias A 'enum1' | 'enum2' ---@type A local ]] TEST [['enum1'|'enum2']] [[ ---@alias A 'enum1' | 'enum2' | A ---@type A local ]] TEST [['enum1'|'enum2'|B]] [[ ---@alias A 'enum1' | 'enum2' | B ---@type A local ]] TEST '1|true' [[ ---@alias A 1 | true ---@type A local ]] TEST 'fun()' [[ ---@type fun() local ]] TEST 'fun(a: string, b: any, ...: any)' [[ ---@type fun(a: string, b, ...) local ]] TEST 'fun(a: string, b: any, c?: boolean, ...: any):c, d?, ...' [[ ---@type fun(a: string, b, c?: boolean, ...):c, d?, ... local ]] TEST 'table' [[ ---@type { [string]: string } local ]] TEST 'table' [[ ---@class string ---@class number ---@type table local ]] TEST 'A' [[ ---@class A ---@type A local ]] TEST 'string' [[ ---@class string ---@type string[] local x local = x[1] ]] TEST 'string' [[ ---@class string ---@return string[] local function f() end local x = f() local = x[1] ]] TEST 'table' [[ local t = {} local = setmetatable(t) ]] TEST 'CCC' [[ ---@class CCC ---@type table local t = {} print(t.) ]] TEST [['aaa'|'bbb']] [[ ---@type table local t = {} print(t.) ]] TEST 'integer' [[ ---@generic K ---@type fun(a?: K):K local f local = f(1) ]] TEST 'unknown' [[ ---@generic K ---@type fun(a?: K):K local f local = f(nil) ]] TEST 'unknown' [[ ---@generic K ---@type fun(a: K|integer):K local f local = f(1) ]] TEST 'integer' [[ ---@class integer ---@generic T: table, V ---@param t T ---@return fun(table: V[], i?: integer):integer, V ---@return T ---@return integer i local function ipairs() end for in ipairs() do end ]] TEST 'table' [[ ---@generic K, V ---@param t table ---@return K ---@return V local function next(t) end ---@type table local t local k, v = next() ]] TEST 'string' [[ ---@class string ---@generic K, V ---@param t table ---@return K ---@return V local function next(t) end ---@type table local t local , v = next(t) ]] TEST 'boolean' [[ ---@class boolean ---@generic K, V ---@param t table ---@return K ---@return V local function next(t) end ---@type table local t local k, = next(t) ]] TEST 'boolean' [[ ---@generic K ---@type fun(arg: K):K local f local = f(true) ]] TEST 'string' [[ ---@class string ---@generic K, V ---@type fun(arg: table):K, V local f ---@type table local t local , v = f(t) ]] TEST 'boolean' [[ ---@class boolean ---@generic K, V ---@type fun(arg: table):K, V local f ---@type table local t local k, = f(t) ]] TEST 'fun()' [[ ---@return fun() local function f() end local = f() ]] TEST 'table' [[ ---@return table local function f() end local = f() ]] TEST 'string' [[ ---@class string ---@generic K, V ---@return fun(arg: table):K, V local function f() end local f2 = f() ---@type table local t local , v = f2(t) ]] TEST 'fun(a: ):integer, ' [[ ---@generic K, V ---@param a K ---@return fun(a: V):K, V local function f(a) end local = f(1) ]] TEST 'integer' [[ ---@generic K, V ---@param a K ---@return fun(a: V):K, V local function f(a) end local f2 = f(1) local , v = f2(true) ]] TEST 'boolean' [[ ---@generic K, V ---@param a K ---@return fun(a: V):K, V local function f(a) end local f2 = f(1) local i, = f2(true) ]] TEST 'fun(table: table<, >, index?: ):, ' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T ---@return nil local function pairs(t) end local = pairs(dummy) ]] TEST 'string' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T ---@return nil local function pairs(t) end local next = pairs(dummy) ---@type table local t local , v = next(t) ]] TEST 'boolean' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T ---@return nil local function pairs(t) end local next = pairs(dummy) ---@type table local t local k, = next(t) ]] TEST 'string' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T ---@return nil local function pairs(t) end local next = pairs(dummy) ---@type table local t local , v = next(t, nil) ]] TEST 'boolean' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T ---@return nil local function pairs(t) end local next = pairs(dummy) ---@type table local t local k, = next(t, nil) ]] TEST 'string' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T ---@return nil local function pairs(t) end local next = pairs(dummy) ---@type table local t for , v in next, t do end ]] TEST 'boolean' [[ ---@class boolean ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T local function pairs(t) end local f = pairs(t) ---@type table local t for k, in f, t do end ]] TEST 'string' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T local function pairs(t) end ---@type table local t for , v in pairs(t) do end ]] TEST 'boolean' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index: K):K, V ---@return T ---@return nil local function pairs(t) end ---@type table local t for k, in pairs(t) do end ]] TEST 'boolean' [[ ---@generic T: table, V ---@param t T ---@return fun(table: V[], i?: integer):integer, V ---@return T ---@return integer i local function ipairs(t) end ---@type boolean[] local t for _, in ipairs(t) do end ]] TEST 'boolean' [[ ---@generic T: table, V ---@param t T ---@return fun(table: V[], i?: integer):integer, V ---@return T ---@return integer i local function ipairs(t) end ---@type table local t for _, in ipairs(t) do end ]] TEST 'boolean' [[ ---@generic T: table, V ---@param t T ---@return fun(table: V[], i?: integer):integer, V ---@return T ---@return integer i local function ipairs(t) end ---@class MyClass ---@field [integer] boolean local t for _, in ipairs(t) do end ]] TEST 'boolean' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index: K):K, V ---@return T ---@return nil local function pairs(t) end ---@type boolean[] local t for k, in pairs(t) do end ]] TEST 'integer' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index?: K):K, V ---@return T local function pairs(t) end ---@type boolean[] local t for , v in pairs(t) do end ]] TEST 'E' [[ ---@class A ---@class B: A ---@class C: B ---@class D: C ---@class E: D local m function m:f() return end ]] TEST 'Cls' [[ ---@class Cls local Cls = {} ---@generic T ---@param self T ---@return T function Cls.new(self) return self end local = Cls:new() ]] TEST 'Cls' [[ ---@class Cls local Cls = {} ---@generic T ---@param self T ---@return T function Cls:new() return self end local = Cls:new() ]] TEST 'Cls' [[ ---@class Cls local Cls = {} ---@generic T ---@param self T ---@return T function Cls.new(self) return self end local = Cls.new(Cls) ]] TEST 'Cls' [[ ---@class Cls local Cls = {} ---@generic T ---@param self T ---@return T function Cls:new() return self end local = Cls.new(Cls) ]] TEST 'Rct' [[ ---@class Obj local Obj = {} ---@generic T ---@param self T ---@return T function Obj.new(self) return self end ---@class Pnt:Obj local Pnt = {x = 0, y = 0} ---@class Rct:Pnt local Rct = {w = 0, h = 0} local = Rct.new(Rct) -- local test = Rct:new() return test ]] TEST 'function' [[ string.gsub():gsub():() ]] config.set(nil, 'Lua.hover.enumsLimit', 5) TEST [['a'|'b'|'c'|'d'|'e'...(+5)]] [[ ---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j' local ]] config.set(nil, 'Lua.hover.enumsLimit', 1) TEST [['a'...(+9)]] [[ ---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j' local ]] config.set(nil, 'Lua.hover.enumsLimit', 0) TEST '...(+10)' [[ ---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j' local ]] config.set(nil, 'Lua.hover.enumsLimit', 5) TEST 'string|fun():string' [[ ---@type string | fun(): string local ]] TEST 'string' [[ local valids = { ['Lua 5.1'] = false, ['Lua 5.2'] = false, ['Lua 5.3'] = false, ['Lua 5.4'] = false, ['LuaJIT'] = false, } for , v in pairs(valids) do end ]] TEST 'boolean' [[ local valids = { ['Lua 5.1'] = false, ['Lua 5.2'] = false, ['Lua 5.3'] = false, ['Lua 5.4'] = false, ['LuaJIT'] = false, } for k, in pairs(valids) do end ]] TEST 'string' [[ local t = { a = 1, b = 1, } for , v in pairs(t) do end ]] TEST 'integer' [[ local t = {'a', 'b'} for , v in pairs(t) do end ]] TEST 'string' [[ local t = {'a', 'b'} for k, in pairs(t) do end ]] TEST 'fun():number, boolean' [[ ---@type fun():number, boolean local ]] TEST 'fun(value: Class)' [[ ---@class Class ---@param callback fun(value: Class) function work(callback) end work( (value) end) ]] TEST 'Class' [[ ---@class Class ---@param callback fun(value: Class) function work(callback) end work(function () end) ]] TEST 'fun(value: Class)' [[ ---@class Class ---@param callback fun(value: Class) function work(callback) end pcall(work, (value) end) ]] TEST 'Class' [[ ---@class Class ---@param callback fun(value: Class) function work(callback) end xpcall(work, debug.traceback, function () end) ]] TEST 'string' [[ ---@generic T ---@param x T ---@return { x: T } local function f(x) end local t = f('') print(t.) ]] TEST 'string' [[ ---@generic T ---@param t T[] ---@param callback fun(v: T) local function f(t, callback) end ---@type string[] local t f(t, function () end) ]] TEST 'unknown' [[ ---@generic T ---@param t T[] ---@param callback fun(v: T) local function f(t, callback) end local t = {} f(t, function () end) ]] TEST 'table' [[ local = setmetatable({}, { __index = function () end }) ]] TEST 'player' [[ ---@class player local t :getOwner() ]] TEST 'string[][]' [[ ---@type string[][] local ]] TEST 'table' [[ ---@type {}[] local t local = t[1] ]] TEST 'string' [[ ---@type string[][] local v = {} for _, a in ipairs(v) do for i, in ipairs(a) do end end ]] --TEST 'number' [[ -----@param x number --local f -- --f = function () end --]] TEST 'fun(i: integer)' [[ --- @class Emit --- @field on fun(eventName: string, cb: function) --- @field on fun(eventName: 'died', cb: fun(i: integer)) --- @field on fun(eventName: 'won', cb: fun(s: string)) local emit = {} emit.on("died", (i) end) ]] TEST 'integer' [[ --- @class Emit --- @field on fun(eventName: string, cb: function) --- @field on fun(eventName: 'died', cb: fun(i: integer)) --- @field on fun(eventName: 'won', cb: fun(s: string)) local emit = {} emit.on("died", function () end) ]] TEST 'integer' [[ --- @class Emit --- @field on fun(self: Emit, eventName: string, cb: function) --- @field on fun(self: Emit, eventName: 'died', cb: fun(i: integer)) --- @field on fun(self: Emit, eventName: 'won', cb: fun(s: string)) local emit = {} emit:on("died", function () end) ]] TEST 'integer' [[ --- @class Emit --- @field on fun(self: Emit, eventName: string, cb: function) --- @field on fun(self: Emit, eventName: '"died"', cb: fun(i: integer)) --- @field on fun(self: Emit, eventName: '"won"', cb: fun(s: string)) local emit = {} emit.on(self, "died", function () end) ]] TEST '👍' [[ ---@class 👍 local ]] TEST 'integer' [[ ---@type boolean local x = 1 ]] TEST 'integer' [[ ---@class Class local x = 1 ]] TEST 'unknown' [[ ---@return number local function f(x) local = x() end ]] TEST 'unknown' [[ local mt ---@return number function mt:f() end local = mt() ]] TEST 'unknown' [[ local ---@class X function mt:f(x) end ]] TEST 'any' [[ local mt ---@class X function mt:f() end ]] TEST 'unknown' [[ local ---@type number function mt:f(x) end ]] TEST 'any' [[ local mt ---@type number function mt:f() end ]] TEST 'Test' [[ ---@class Test _G. = {} ]] TEST 'integer' [[ local mt = {} ---@param callback fun(i: integer) function mt:loop(callback) end mt:loop(function () end) ]] TEST 'C' [[ ---@class D ---@field y integer # D comment ---@class C ---@field x integer # C comment ---@field d D ---@param c C local function f(c) end f x = , } ]] TEST 'integer' [[ ---@class D ---@field y integer # D comment ---@class C ---@field x integer # C comment ---@field d D ---@param c C local function f(c) end f { = , } ]] TEST 'integer' [[ ---@class D ---@field y integer # D comment ---@class C ---@field x integer # C comment ---@field d D ---@param c C local function f(c) end f { d = { = , } } ]] TEST 'integer' [[ for = a, b, c do end ]] TEST 'number' [[ ---@param x number function F() end ---@param x boolean function F(x) end ]] TEST 'B' [[ ---@class A local A ---@return A function A:x() end ---@class B: A local B ---@return B function B:x() end ---@type B local t local = t.x() ]] TEST 'function' [[ ---@overload fun() function () end ]] TEST 'integer' [[ ---@type table local t t. ]] TEST '"a"|"b"|"c"' [[ ---@type table local t t. ]] TEST 'integer' [[ ---@class A ---@field x integer ---@type A local t t. ]] TEST 'boolean' [[ local = true var = 1 var = 1.0 ]] TEST 'unknown' [[ ---@return ... local function f() end local = f() ]] TEST 'unknown' [[ ---@return ... local function f() end local _, = f() ]] TEST 'unknown' [[ local t = { x = 1, y = 2, } local = t[#t] ]] TEST 'string' [[ local t = { x = 1, [1] = 'x', } local = t[#t] ]] TEST 'string' [[ local t = { 'x' } local = t[#t] ]] TEST '(string|integer)[]' [[ ---@type (string|integer)[] local ]] TEST 'boolean' [[ ---@type table local t ---@alias uri string ---@type string local uri local = t[uri] ]] TEST 'A' [[ ---@class A G = {} :A() ]] TEST 'A' [[ ---@type A local = nil ]] TEST 'A' [[ ---@class A ---@field b B local mt function mt:f() self.b:x() print() end ]] TEST 'string?' [[ ---@return string? local function f() end local = f() ]] TEST 'AA' [[ ---@class AA ---@overload fun():AA local AAA local = AAA() ]] TEST 'string|integer' [[ local x = '1' x = 1 ]] TEST 'string' [[ local x = '1' x = 1 ]] TEST 'integer' [[ local x x = '1' = 1 ]] TEST 'unknown' [[ local x print() x = '1' x = 1 ]] TEST 'string' [[ local x x = '1' print() x = 1 ]] TEST 'integer' [[ local x x = '1' x = 1 print() ]] TEST 'unknown' [[ local x function A() print() end ]] TEST 'unknown' [[ local x function A() print() end x = '1' x = 1 ]] TEST 'string' [[ local x x = '1' function A() print() end x = 1 ]] TEST 'integer' [[ local x x = '1' x = 1 function A() print() end ]] TEST 'boolean' [[ local x function A() x = true print() end x = '1' x = 1 ]] TEST 'unknown' [[ local x function A() x = true end print() x = '1' x = 1 ]] TEST 'boolean' [[ local x function A() x = true function B() print() end end x = '1' x = 1 ]] TEST 'table' [[ local x function A() x = true function B() x = {} print() end end x = '1' x = 1 ]] TEST 'boolean' [[ local x function A() x = true function B() x = {} end print() end x = '1' x = 1 ]] TEST 'unknown' [[ local x function A() x = true function B() x = {} end end function C() print() end x = '1' x = 1 ]] TEST 'integer?' [[ ---@type integer? local ]] TEST 'integer?' [[ ---@type integer? local x if then print(x) end ]] --[[ context 0 integer? save copy 'block' save copy 'out' push 'block' get push copy truthy falsy ref 'out' get save HEAD 'final' push 'out' push copy HEAD merge 'final' ]] TEST 'integer' [[ ---@type integer? local x if x then print() end ]] TEST 'integer?' [[ ---@type integer? local x if x then print(x) end print() ]] TEST 'integer' [[ ---@type integer? local x if not x then x = 1 end print() ]] TEST 'integer' [[ ---@type integer? local x if xxx and x then print() end ]] TEST 'integer?' [[ ---@type integer? local x if xxx and x then end print() ]] TEST 'integer?' [[ ---@type integer? local x if xxx and x then return end print() ]] TEST 'integer' [[ ---@type integer? local x if x ~= nil then print() end print(x) ]] TEST 'integer|nil' [[ ---@type integer? local x if x ~= nil then print(x) end print() ]] TEST 'nil' [[ ---@type integer? local x if x == nil then print() end print(x) ]] TEST 'integer|nil' [[ ---@type integer? local x if x == nil then print(x) end print() ]] TEST 'integer' [[ ---@type integer? local x = x or 1 ]] TEST 'integer' [[ ---@type integer? local x = x or y ]] TEST 'integer' [[ ---@type integer? local x if not x then return end print() ]] TEST 'integer' [[ ---@type integer? local x if not x then goto ANYWHERE end print() ]] TEST 'integer' [=[ local x print(--[[@as integer]]) ]=] TEST 'integer' [=[ print(--[[@as integer]]) ]=] TEST 'integer' [=[ print(io.--[[@as integer]]) ]=] TEST 'integer' [=[ local = io['open']--[[@as integer]]) ]=] TEST 'integer' [=[ local = 1 + 1--[[@as integer]]) ]=] TEST 'integer' [=[ local = not 1--[[@as integer]]) ]=] TEST 'integer' [=[ local = ()--[[@as integer]]) ]=] TEST 'integer?' [[ ---@param x? integer local function f() end ]] TEST 'integer' [[ local x = 1 x = ]] TEST 'integer?' [[ ---@class A ---@field x? integer local t t. ]] TEST 'integer?' [[ ---@type { x?: integer } local t t. ]] TEST 'boolean' [[ ---@class A ---@field [integer] boolean local t local = t[1] ]] TEST 'unknown' [[ local = y and z ]] TEST 'integer' [[ ---@type integer? local x assert(x) print() ]] TEST 'integer' [[ ---@type integer? local x assert(x ~= nil) print() ]] TEST 'integer' [[ ---@type integer | nil local x assert(x) print() ]] TEST 'integer' [[ ---@type integer | nil local x assert(x ~= nil) print() ]] TEST 'integer' [[ local x assert(x == 1) print() ]] TEST 'integer' [[ ---@type integer? local x if x and .y then end ]] TEST 'integer?' [[ ---@type integer? local x if x and x.y then end print() ]] TEST 'integer?' [[ ---@type integer? local x if x and x.y then return end print() ]] TEST 'integer' [[ ---@type integer? local x if not x or .y then end ]] TEST 'integer?' [[ ---@type integer? local x if not x or x.y then print() end ]] TEST 'integer?' [[ ---@type integer? local x if x or x.y then print() end ]] TEST 'integer?' [[ ---@type integer? local x if x.y or x then print() end ]] TEST 'integer?' [[ ---@type integer? local x if x.y or not x then print() end ]] TEST 'integer' [[ ---@type integer? local x if not x or not y then return end print() ]] TEST 'integer' [[ ---@type integer? local x if not y or not x then return end print() ]] TEST 'integer' [[ ---@type integer? local x while true do if not x then break end print() end ]] TEST 'integer?' [[ ---@type integer? local x while true do if not x then break end end print() ]] TEST 'integer' [[ ---@type fun():integer? local iter for in iter do end ]] TEST 'integer' [[ local x ---@type integer = XXX ]] TEST 'unknown' [[ for _ = 1, 999 do local end ]] TEST 'integer' [[ local x ---@cast x integer print() ]] TEST 'unknown' [[ local x ---@cast x integer local x print() ]] TEST 'unknown' [[ local x if true then local x ---@cast x integer print(x) end print() ]] TEST 'boolean|integer' [[ local x = 1 ---@cast x +boolean print() ]] TEST 'boolean' [[ ---@type integer|boolean local x ---@cast x -integer print() ]] TEST 'boolean?' [[ ---@type boolean local x ---@cast x +? print() ]] TEST 'boolean' [[ ---@type boolean? local x ---@cast x -? print() ]] TEST 'string' [[ ---@type string? local x if not x then return else print() end print(x) ]] TEST 'string' [[ ---@type string? local x if not x then return else print(x) end print() ]] TEST 'true' [[ ---@type boolean | nil local x if not x then return end print() ]]